mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 13:00:19 +00:00
Merge pull request #21104 from segayuu/request-cleanup-ignore-lint-errors
[@types/request] cleanup ignore lint errors
This commit is contained in:
Vendored
+20
-21
@@ -1,6 +1,11 @@
|
||||
// Type definitions for request 2.0
|
||||
// Project: https://github.com/request/request
|
||||
// Definitions by: Carlos Ballesteros Velasco <https://github.com/soywiz>, bonnici <https://github.com/bonnici>, Bart van der Schoor <https://github.com/Bartvds>, Joe Skeen <https://github.com/joeskeen>, Christopher Currens <https://github.com/ccurrens>, Jon Stevens <https://github.com/lookfirst>
|
||||
// Definitions by: Carlos Ballesteros Velasco <https://github.com/soywiz>,
|
||||
// bonnici <https://github.com/bonnici>,
|
||||
// Bart van der Schoor <https://github.com/Bartvds>,
|
||||
// Joe Skeen <https://github.com/joeskeen>,
|
||||
// Christopher Currens <https://github.com/ccurrens>,
|
||||
// Jon Stevens <https://github.com/lookfirst>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
@@ -17,10 +22,7 @@ import FormData = require('form-data');
|
||||
import { Url } from 'url';
|
||||
|
||||
declare namespace request {
|
||||
export interface RequestAPI<TRequest extends Request,
|
||||
TOptions extends CoreOptions,
|
||||
TUriUrlOptions> {
|
||||
|
||||
export interface RequestAPI<TRequest extends Request, TOptions extends CoreOptions, TUriUrlOptions> {
|
||||
defaults(options: TOptions): RequestAPI<TRequest, TOptions, RequiredUriUrl>;
|
||||
defaults(options: RequiredUriUrl & TOptions): DefaultUriUrlRequestApi<TRequest, TOptions, OptionalUriUrl>;
|
||||
|
||||
@@ -65,9 +67,8 @@ declare namespace request {
|
||||
}
|
||||
|
||||
interface DefaultUriUrlRequestApi<TRequest extends Request,
|
||||
TOptions extends CoreOptions,
|
||||
TUriUrlOptions> extends RequestAPI<TRequest, TOptions, TUriUrlOptions> {
|
||||
|
||||
TOptions extends CoreOptions,
|
||||
TUriUrlOptions> extends RequestAPI<TRequest, TOptions, TUriUrlOptions> {
|
||||
defaults(options: TOptions): DefaultUriUrlRequestApi<TRequest, TOptions, OptionalUriUrl>;
|
||||
(callback?: RequestCallback): TRequest;
|
||||
|
||||
@@ -173,13 +174,11 @@ declare namespace request {
|
||||
export type OptionsWithUrl = UrlOptions & CoreOptions;
|
||||
export type Options = OptionsWithUri | OptionsWithUrl;
|
||||
|
||||
export interface RequestCallback {
|
||||
(error: any, response: RequestResponse, body: any): void;
|
||||
}
|
||||
export type RequestCallback = (error: any, response: RequestResponse, body: any) => void;
|
||||
|
||||
export type ResponseRequest = CoreOptions & {
|
||||
uri: Url;
|
||||
}
|
||||
};
|
||||
|
||||
export interface RequestResponse extends http.IncomingMessage {
|
||||
request: ResponseRequest;
|
||||
@@ -209,7 +208,7 @@ declare namespace request {
|
||||
postData?: {
|
||||
mimeType?: string;
|
||||
params?: NameValuePair[];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export interface NameValuePair {
|
||||
@@ -219,10 +218,10 @@ declare namespace request {
|
||||
|
||||
export interface Multipart {
|
||||
chunked?: boolean;
|
||||
data?: {
|
||||
data?: Array<{
|
||||
'content-type'?: string,
|
||||
body: string
|
||||
}[];
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface RequestPart {
|
||||
@@ -235,8 +234,8 @@ declare namespace request {
|
||||
writable: boolean;
|
||||
|
||||
getAgent(): http.Agent;
|
||||
//start(): void;
|
||||
//abort(): void;
|
||||
// start(): void;
|
||||
// abort(): void;
|
||||
pipeDest(dest: any): void;
|
||||
setHeader(name: string, value: string, clobber?: boolean): Request;
|
||||
setHeaders(headers: Headers): Request;
|
||||
@@ -293,7 +292,7 @@ declare namespace request {
|
||||
token_secret?: string;
|
||||
transport_method?: 'body' | 'header' | 'query';
|
||||
verifier?: string;
|
||||
body_hash?: true | string
|
||||
body_hash?: true | string;
|
||||
}
|
||||
|
||||
export interface HawkOptions {
|
||||
@@ -306,9 +305,9 @@ declare namespace request {
|
||||
}
|
||||
|
||||
export interface CookieJar {
|
||||
setCookie(cookie: Cookie, uri: string | url.Url, options?: any): void
|
||||
getCookieString(uri: string | url.Url): string
|
||||
getCookies(uri: string | url.Url): Cookie[]
|
||||
setCookie(cookie: Cookie, uri: string | url.Url, options?: any): void;
|
||||
getCookieString(uri: string | url.Url): string;
|
||||
getCookies(uri: string | url.Url): Cookie[];
|
||||
}
|
||||
|
||||
export interface CookieValue {
|
||||
|
||||
+126
-131
@@ -1,10 +1,10 @@
|
||||
|
||||
import request = require('request');
|
||||
import http = require('http');
|
||||
import stream = require('stream');
|
||||
import urlModule = require('url');
|
||||
import fs = require('fs');
|
||||
import FormData = require('form-data');
|
||||
import path = require('path');
|
||||
|
||||
var value: any;
|
||||
var str: string;
|
||||
@@ -33,12 +33,12 @@ var bodyArr: request.RequestPart[] = [{
|
||||
body: value
|
||||
}];
|
||||
|
||||
//Defaults tests
|
||||
// Defaults tests
|
||||
(() => {
|
||||
const githubUrl = 'https://github.com';
|
||||
const defaultJarRequest = request.defaults({ jar: true });
|
||||
defaultJarRequest.get(githubUrl);
|
||||
//defaultJarRequest(); //this line doesn't compile (and shouldn't)
|
||||
// defaultJarRequest(); //this line doesn't compile (and shouldn't)
|
||||
const defaultUrlRequest = request.defaults({ url: githubUrl });
|
||||
defaultUrlRequest();
|
||||
defaultUrlRequest.get();
|
||||
@@ -48,7 +48,6 @@ var bodyArr: request.RequestPart[] = [{
|
||||
defaultBodyRequest.put();
|
||||
})();
|
||||
|
||||
|
||||
// --- --- --- --- --- --- --- --- --- --- --- ---
|
||||
|
||||
obj = req.toJSON();
|
||||
@@ -90,21 +89,15 @@ strOrTrueOrUndef = oauth.body_hash;
|
||||
var options: request.Options = {
|
||||
url: str,
|
||||
uri: str,
|
||||
callback: (error: any, response: any, body: any) => {
|
||||
|
||||
},
|
||||
callback: (error: any, response: any, body: any) => {},
|
||||
jar: value,
|
||||
form: obj,
|
||||
oauth: value,
|
||||
aws: aws,
|
||||
qs: obj,
|
||||
json: value,
|
||||
jsonReviver: (key: string, value: any) => {
|
||||
|
||||
},
|
||||
jsonReplacer: (key: string, value: any) => {
|
||||
|
||||
},
|
||||
jsonReviver: (key: string, value: any) => {},
|
||||
jsonReplacer: (key: string, value: any) => {},
|
||||
multipart: value,
|
||||
agent: new http.Agent(),
|
||||
agentOptions: value,
|
||||
@@ -139,8 +132,8 @@ opt.uri = str;
|
||||
// --- --- --- --- --- --- --- --- --- --- --- ---
|
||||
|
||||
agent = req.getAgent();
|
||||
//req.start();
|
||||
//req.abort();
|
||||
// req.start();
|
||||
// req.abort();
|
||||
req.pipeDest(dest);
|
||||
req = req.setHeader(str, str);
|
||||
req = req.setHeader(str, str, bool);
|
||||
@@ -241,14 +234,14 @@ r.post(options);
|
||||
|
||||
request
|
||||
.get('http://example.com/example.png')
|
||||
.on('response', function(response: any) {
|
||||
.on('response', (response: any) => {
|
||||
// check response
|
||||
})
|
||||
.pipe(request.put('http://another.com/another.png'));
|
||||
|
||||
//The following examples from https://github.com/request/request
|
||||
request('http://www.google.com', function (error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
// The following examples from https://github.com/request/request
|
||||
request('http://www.google.com', (error, response, body) => {
|
||||
if (!error && response.statusCode === 200) {
|
||||
console.log(body); // Show the HTML for the Google homepage.
|
||||
}
|
||||
});
|
||||
@@ -261,7 +254,7 @@ request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img
|
||||
|
||||
request
|
||||
.get('http://google.com/img.png')
|
||||
.on('response', function(response: any) {
|
||||
.on('response', (response: any) => {
|
||||
console.log(response.statusCode); // 200
|
||||
console.log(response.headers['content-type']); // 'image/png'
|
||||
})
|
||||
@@ -269,22 +262,25 @@ request
|
||||
|
||||
request
|
||||
.get('http://mysite.com/doodle.png')
|
||||
.on('error', function(err: any) {
|
||||
.on('error', (err: any) => {
|
||||
console.log(err);
|
||||
})
|
||||
.pipe(fs.createWriteStream('doodle.png'));
|
||||
|
||||
http.createServer(function (req, resp) {
|
||||
http.createServer((req, resp) => {
|
||||
if (req.url === '/doodle.png') {
|
||||
if (req.method === 'PUT') {
|
||||
req.pipe(request.put('http://mysite.com/doodle.png'));
|
||||
} else if (req.method === 'GET' || req.method === 'HEAD') {
|
||||
request.get('http://mysite.com/doodle.png').pipe(resp);
|
||||
switch (req.method) {
|
||||
case 'PUT':
|
||||
req.pipe(request.put('http://mysite.com/doodle.png'));
|
||||
break;
|
||||
case 'GET':
|
||||
case 'HEAD':
|
||||
request.get('http://mysite.com/doodle.png').pipe(resp);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
http.createServer(function (req, resp) {
|
||||
http.createServer((req, resp) => {
|
||||
if (req.url === '/doodle.png') {
|
||||
var x = request('http://mysite.com/doodle.png');
|
||||
req.pipe(x);
|
||||
@@ -292,21 +288,21 @@ http.createServer(function (req, resp) {
|
||||
}
|
||||
});
|
||||
|
||||
http.createServer(function (req, resp) {
|
||||
http.createServer((req, resp) => {
|
||||
req.pipe(request('http://mysite.com/doodle.png')).pipe(resp);
|
||||
});
|
||||
|
||||
http.createServer(function (req, resp) {
|
||||
http.createServer((req, resp) => {
|
||||
if (req.url === '/doodle.png') {
|
||||
r.get('http://google.com/doodle.png').pipe(resp);
|
||||
}
|
||||
});
|
||||
|
||||
request.post('http://service.com/upload', {form:{key:'value'}});
|
||||
request.post('http://service.com/upload', {form: {key: 'value'}});
|
||||
// or
|
||||
request.post('http://service.com/upload').form({key:'value'});
|
||||
request.post('http://service.com/upload').form({key: 'value'});
|
||||
// or
|
||||
request.post({url:'http://service.com/upload', form: {key:'value'}}, function(err,httpResponse,body){ /* ... */ });
|
||||
request.post({url: 'http://service.com/upload', form: {key: 'value'}}, (err, httpResponse, body) => { /* ... */ });
|
||||
|
||||
var data = {
|
||||
// Pass a simple key-value pair
|
||||
@@ -331,9 +327,10 @@ var data = {
|
||||
}
|
||||
}
|
||||
};
|
||||
request.post({url:'http://service.com/upload', formData: data}, function optionalCallback(err, httpResponse, body) {
|
||||
request.post({url: 'http://service.com/upload', formData: data}, function optionalCallback(err, httpResponse, body) {
|
||||
if (err) {
|
||||
return console.error('upload failed:', err);
|
||||
console.error('upload failed:', err);
|
||||
return;
|
||||
}
|
||||
console.log('Upload successful! Server responded with:', body);
|
||||
});
|
||||
@@ -354,15 +351,16 @@ request({
|
||||
data: [
|
||||
{
|
||||
'content-type': 'application/json',
|
||||
body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
|
||||
body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, content_type: 'text/plain' }}})
|
||||
},
|
||||
{ body: 'I am an attachment' }
|
||||
]
|
||||
}
|
||||
},
|
||||
function (error, response, body) {
|
||||
(error, response, body) => {
|
||||
if (error) {
|
||||
return console.error('upload failed:', error);
|
||||
console.error('upload failed:', error);
|
||||
return;
|
||||
}
|
||||
console.log('Upload successful! Server responded with:', body);
|
||||
});
|
||||
@@ -374,15 +372,16 @@ request({
|
||||
multipart: [
|
||||
{
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
|
||||
body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, content_type: 'text/plain' }}})
|
||||
},
|
||||
{ body: 'I am an attachment' },
|
||||
{ body: fs.createReadStream('image.png') }
|
||||
]
|
||||
},
|
||||
function (error, response, body) {
|
||||
(error, response, body) => {
|
||||
if (error) {
|
||||
return console.error('upload failed:', error);
|
||||
console.error('upload failed:', error);
|
||||
return;
|
||||
}
|
||||
console.log('Upload successful! Server responded with:', body);
|
||||
});
|
||||
@@ -390,32 +389,32 @@ request({
|
||||
request.get('http://some.server.com/').auth('username', 'password', false);
|
||||
// or
|
||||
request.get('http://some.server.com/', {
|
||||
'auth': {
|
||||
'user': 'username',
|
||||
'pass': 'password',
|
||||
'sendImmediately': false
|
||||
auth: {
|
||||
user: 'username',
|
||||
pass: 'password',
|
||||
sendImmediately: false
|
||||
}
|
||||
});
|
||||
// or
|
||||
request.get('http://some.server.com/').auth('foo', 'bar', true, 'bearerToken');
|
||||
// or
|
||||
request.get('http://some.server.com/', {
|
||||
'auth': {
|
||||
'bearer': 'bearerToken'
|
||||
auth: {
|
||||
bearer: 'bearerToken'
|
||||
}
|
||||
});
|
||||
// or
|
||||
request.get('http://some.server.com/', {
|
||||
'auth': {
|
||||
'bearer': () => 'bearerToken'
|
||||
auth: {
|
||||
bearer: () => 'bearerToken'
|
||||
}
|
||||
});
|
||||
|
||||
var username = 'username',
|
||||
password = 'password',
|
||||
url = 'http://' + username + ':' + password + '@some.server.com';
|
||||
let username = 'username';
|
||||
let password = 'password';
|
||||
var url = `http://'${username}:${password}'@some.server.com`;
|
||||
|
||||
request({url: url}, function (error, response, body) {
|
||||
request({url: url}, (error, response, body) => {
|
||||
// Do more stuff with 'body' here
|
||||
});
|
||||
|
||||
@@ -427,7 +426,7 @@ options = {
|
||||
};
|
||||
|
||||
function callback(error: any, response: http.IncomingMessage, body: string) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
if (!error && response.statusCode === 200) {
|
||||
var info = JSON.parse(body);
|
||||
console.log(info.stargazers_count + " Stars");
|
||||
console.log(info.forks_count + " Forks");
|
||||
@@ -441,15 +440,15 @@ request(options, callback);
|
||||
import qs = require('querystring');
|
||||
const CONSUMER_KEY = 'key';
|
||||
const CONSUMER_SECRET = 'secret';
|
||||
oauth =
|
||||
{ callback: 'http://mysite.com/callback/'
|
||||
, consumer_key: CONSUMER_KEY
|
||||
, consumer_secret: CONSUMER_SECRET
|
||||
, transport_method: 'header'
|
||||
}
|
||||
, url = 'https://api.twitter.com/oauth/request_token'
|
||||
;
|
||||
request.post({url:url, oauth:oauth}, function (e, r, body) {
|
||||
oauth = {
|
||||
callback: 'http://mysite.com/callback/',
|
||||
consumer_key: CONSUMER_KEY,
|
||||
consumer_secret: CONSUMER_SECRET,
|
||||
transport_method: 'header'
|
||||
};
|
||||
url = 'https://api.twitter.com/oauth/request_token';
|
||||
|
||||
request.post({url: url, oauth: oauth}, (e, r, body) => {
|
||||
// Ideally, you would take the body in the response
|
||||
// and construct a URL that a user clicks on (like a sign in button).
|
||||
// The verifier is only available in the response after a user has
|
||||
@@ -457,46 +456,44 @@ request.post({url:url, oauth:oauth}, function (e, r, body) {
|
||||
|
||||
// step 2
|
||||
var req_data = qs.parse(body);
|
||||
var uri = 'https://api.twitter.com/oauth/authenticate'
|
||||
+ '?' + qs.stringify({oauth_token: req_data.oauth_token});
|
||||
var uri = `https://api.twitter.com/oauth/authenticate?${qs.stringify({oauth_token: req_data.oauth_token})}`;
|
||||
// redirect the user to the authorize uri
|
||||
|
||||
// step 3
|
||||
// after the user is redirected back to your server
|
||||
var auth_data: any = qs.parse(body)
|
||||
, oauth =
|
||||
{ consumer_key: CONSUMER_KEY
|
||||
, consumer_secret: CONSUMER_SECRET
|
||||
, token: auth_data.oauth_token
|
||||
, token_secret: req_data.oauth_token_secret as string
|
||||
, verifier: auth_data.oauth_verifier
|
||||
}
|
||||
, url = 'https://api.twitter.com/oauth/access_token'
|
||||
;
|
||||
request.post({url:url, oauth:oauth}, function (e, r, body) {
|
||||
var auth_data: any = qs.parse(body);
|
||||
var oauth = {
|
||||
consumer_key: CONSUMER_KEY,
|
||||
consumer_secret: CONSUMER_SECRET,
|
||||
token: auth_data.oauth_token,
|
||||
token_secret: req_data.oauth_token_secret as string,
|
||||
verifier: auth_data.oauth_verifier
|
||||
};
|
||||
var url = 'https://api.twitter.com/oauth/access_token';
|
||||
|
||||
request.post({url: url, oauth: oauth}, (e, r, body) => {
|
||||
// ready to make signed requests on behalf of the user
|
||||
var perm_data: any = qs.parse(body);
|
||||
var oauth =
|
||||
{ consumer_key: CONSUMER_KEY
|
||||
, consumer_secret: CONSUMER_SECRET
|
||||
, token: perm_data.oauth_token
|
||||
, token_secret: perm_data.oauth_token_secret
|
||||
};
|
||||
var oauth = {
|
||||
consumer_key: CONSUMER_KEY,
|
||||
consumer_secret: CONSUMER_SECRET,
|
||||
token: perm_data.oauth_token,
|
||||
token_secret: perm_data.oauth_token_secret
|
||||
};
|
||||
var url = 'https://api.twitter.com/1.1/users/show.json';
|
||||
var query = {
|
||||
screen_name: perm_data.screen_name,
|
||||
user_id: perm_data.user_id
|
||||
};
|
||||
request.get({url:url, oauth:oauth, qs:query, json:true}, function (e, r, user) {
|
||||
request.get({url: url, oauth: oauth, qs: query, json: true}, (e, r, user) => {
|
||||
console.log(user);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var path = require('path')
|
||||
, certFile = path.resolve(__dirname, 'ssl/client.crt')
|
||||
, keyFile = path.resolve(__dirname, 'ssl/client.key')
|
||||
, caFile = path.resolve(__dirname, 'ssl/ca.cert.pem');
|
||||
var certFile = path.resolve(__dirname, 'ssl/client.crt');
|
||||
var keyFile = path.resolve(__dirname, 'ssl/client.key');
|
||||
var caFile = path.resolve(__dirname, 'ssl/ca.cert.pem');
|
||||
|
||||
options = {
|
||||
url: 'https://api.some-server.com/',
|
||||
@@ -508,9 +505,8 @@ options = {
|
||||
|
||||
request.get(options);
|
||||
|
||||
var path = require('path')
|
||||
, certFile = path.resolve(__dirname, 'ssl/client.crt')
|
||||
, keyFile = path.resolve(__dirname, 'ssl/client.key');
|
||||
var certFile = path.resolve(__dirname, 'ssl/client.crt');
|
||||
var keyFile = path.resolve(__dirname, 'ssl/client.key');
|
||||
|
||||
options = {
|
||||
url: 'https://api.some-server.com/',
|
||||
@@ -540,7 +536,6 @@ request.get({
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
request({
|
||||
// will be ignored
|
||||
method: 'GET',
|
||||
@@ -572,19 +567,19 @@ request({
|
||||
}
|
||||
});
|
||||
|
||||
//requests using baseRequest() will set the 'x-token' header
|
||||
// requests using baseRequest() will set the 'x-token' header
|
||||
var baseRequest = request.defaults({
|
||||
headers: {'x-token': 'my-token'}
|
||||
});
|
||||
|
||||
//requests using specialRequest() will include the 'x-token' header set in
|
||||
//baseRequest and will also include the 'special' header
|
||||
// requests using specialRequest() will include the 'x-token' header set in
|
||||
// baseRequest and will also include the 'special' header
|
||||
var specialRequest = baseRequest.defaults({
|
||||
headers: {special: 'special value'}
|
||||
});
|
||||
|
||||
const urlRequest = specialRequest.defaults({url: 'https://github.com'});
|
||||
urlRequest({}, function(error, response, body) {console.log(body);});
|
||||
urlRequest({}, (error, response, body) => { console.log(body); });
|
||||
|
||||
request.put(url);
|
||||
request.patch(url);
|
||||
@@ -597,7 +592,7 @@ request.cookie('key1=value1');
|
||||
request.jar();
|
||||
request.debug = true;
|
||||
|
||||
request.get('http://10.255.255.1', {timeout: 1500}, function(err) {
|
||||
request.get('http://10.255.255.1', {timeout: 1500}, (err) => {
|
||||
console.log(err.code === 'ETIMEDOUT');
|
||||
// Set to `true` if the timeout was a connection timeout, `false` or
|
||||
// `undefined` otherwise.
|
||||
@@ -605,23 +600,23 @@ request.get('http://10.255.255.1', {timeout: 1500}, function(err) {
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
var rand = Math.floor(Math.random()*100000000).toString();
|
||||
var rand = Math.floor(Math.random() * 100000000).toString();
|
||||
request(
|
||||
{ method: 'PUT'
|
||||
, uri: 'http://mikeal.iriscouch.com/testjs/' + rand
|
||||
, multipart:
|
||||
[ { headers: { 'content-type': 'application/json' }
|
||||
, body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
|
||||
, body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, content_type: 'text/plain' }}})
|
||||
}
|
||||
, { body: 'I am an attachment' }
|
||||
]
|
||||
}
|
||||
, function (error, response, body) {
|
||||
if(response.statusCode == 201){
|
||||
console.log('document saved as: http://mikeal.iriscouch.com/testjs/'+ rand)
|
||||
, (error, response, body) => {
|
||||
if (response.statusCode === 201) {
|
||||
console.log('document saved as: http://mikeal.iriscouch.com/testjs/' + rand);
|
||||
} else {
|
||||
console.log('error: '+ response.statusCode)
|
||||
console.log(body)
|
||||
console.log('error: ' + response.statusCode);
|
||||
console.log(body);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -631,31 +626,31 @@ request(
|
||||
, uri: 'http://www.google.com'
|
||||
, gzip: true
|
||||
}
|
||||
, function (error, response, body) {
|
||||
, (error, response, body) => {
|
||||
// body is the decompressed response body
|
||||
console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'identity'))
|
||||
console.log('the decoded data is: ' + body)
|
||||
console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'identity'));
|
||||
console.log('the decoded data is: ' + body);
|
||||
}
|
||||
).on('data', function(data: any) {
|
||||
).on('data', (data: any) => {
|
||||
// decompressed data as it is received
|
||||
console.log('decoded chunk: ' + data)
|
||||
console.log('decoded chunk: ' + data);
|
||||
})
|
||||
.on('response', function(response: http.IncomingMessage) {
|
||||
.on('response', (response: http.IncomingMessage) => {
|
||||
// unmodified http.IncomingMessage object
|
||||
response.on('data', function(data: any[]) {
|
||||
response.on('data', (data: any[]) => {
|
||||
// compressed data as it is received
|
||||
console.log('received ' + data.length + ' bytes of compressed data')
|
||||
})
|
||||
console.log(`received ${data.length} bytes of compressed data`);
|
||||
});
|
||||
});
|
||||
|
||||
var requestWithJar = request.defaults({jar: true})
|
||||
requestWithJar('http://www.google.com', function () {
|
||||
var requestWithJar = request.defaults({jar: true});
|
||||
requestWithJar('http://www.google.com', () => {
|
||||
requestWithJar('http://images.google.com');
|
||||
});
|
||||
|
||||
var j = request.jar()
|
||||
requestWithJar = request.defaults({jar:j})
|
||||
requestWithJar('http://www.google.com', function () {
|
||||
var j = request.jar();
|
||||
requestWithJar = request.defaults({jar: j});
|
||||
requestWithJar('http://www.google.com', () => {
|
||||
requestWithJar('http://images.google.com');
|
||||
});
|
||||
|
||||
@@ -663,21 +658,21 @@ var j = request.jar();
|
||||
cookie = request.cookie('key1=value1');
|
||||
var url = 'http://www.google.com';
|
||||
j.setCookie(cookie, url);
|
||||
request({url: url, jar: j}, function () {
|
||||
request({url: url, jar: j}, () => {
|
||||
request('http://images.google.com');
|
||||
});
|
||||
|
||||
//TODO: add definitions for tough-cookie-filestore
|
||||
//var FileCookieStore = require('tough-cookie-filestore');
|
||||
// TODO: add definitions for tough-cookie-filestore
|
||||
// var FileCookieStore = require('tough-cookie-filestore');
|
||||
// NOTE - currently the 'cookies.json' file must already exist!
|
||||
//var j = request.jar(new FileCookieStore('cookies.json'));
|
||||
requestWithJar = request.defaults({ jar : j })
|
||||
request('http://www.google.com', function() {
|
||||
// var j = request.jar(new FileCookieStore('cookies.json'));
|
||||
requestWithJar = request.defaults({ jar : j });
|
||||
request('http://www.google.com', () => {
|
||||
request('http://images.google.com');
|
||||
});
|
||||
|
||||
var j = request.jar()
|
||||
request({url: 'http://www.google.com', jar: j}, function () {
|
||||
var j = request.jar();
|
||||
request({url: 'http://www.google.com', jar: j}, () => {
|
||||
var cookie_string = j.getCookieString(url); // "key1=value1; key2=value2; ..."
|
||||
var cookies = j.getCookies(url);
|
||||
// [{key: 'key1', value: 'value1', domain: "www.google.com", ...}, ...]
|
||||
@@ -689,11 +684,11 @@ request(
|
||||
, gzip: true
|
||||
}
|
||||
)
|
||||
.on('request', function(req: http.ClientRequest) { })
|
||||
.on('response', function(resp: http.IncomingMessage) { })
|
||||
.on('data', function(data: Buffer | string) { })
|
||||
.on('error', function(e: Error) { })
|
||||
.on('complete', function(resp: http.IncomingMessage, body?: string | Buffer) { });
|
||||
.on('request', (req: http.ClientRequest) => { })
|
||||
.on('response', (resp: http.IncomingMessage) => { })
|
||||
.on('data', (data: Buffer | string) => { })
|
||||
.on('error', (e: Error) => { })
|
||||
.on('complete', (resp: http.IncomingMessage, body?: string | Buffer) => { });
|
||||
|
||||
// options.url / options.uri can be the Url object
|
||||
request.get({
|
||||
@@ -720,11 +715,11 @@ requestWithOptionalUri({ url: urlModule.parse('http://example.com') });
|
||||
|
||||
requestWithOptionalUri('http://example.com');
|
||||
|
||||
requestWithOptionalUri(function() {});
|
||||
requestWithOptionalUri(() => {});
|
||||
|
||||
requestWithOptionalUri.get();
|
||||
|
||||
requestWithOptionalUri.get(function() {});
|
||||
requestWithOptionalUri.get(() => {});
|
||||
|
||||
requestWithOptionalUri.get('http://example.com');
|
||||
|
||||
|
||||
@@ -1,81 +1,14 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-comma-operator": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-switch": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
"unified-signatures": false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user