urllib 2.38.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -264
- package/package.json +62 -59
- package/src/HttpAgent.ts +72 -0
- package/src/HttpClient.ts +514 -0
- package/src/Request.ts +118 -0
- package/src/Response.ts +41 -0
- package/src/cjs/HttpAgent.d.ts +16 -0
- package/src/cjs/HttpAgent.js +62 -0
- package/src/cjs/HttpAgent.js.map +1 -0
- package/src/cjs/HttpClient.d.ts +39 -0
- package/src/cjs/HttpClient.js +466 -0
- package/src/cjs/HttpClient.js.map +1 -0
- package/src/cjs/Request.d.ts +114 -0
- package/src/cjs/Request.js +3 -0
- package/src/cjs/Request.js.map +1 -0
- package/src/cjs/Response.d.ts +36 -0
- package/src/cjs/Response.js +3 -0
- package/src/cjs/Response.js.map +1 -0
- package/src/cjs/index.d.ts +7 -0
- package/src/cjs/index.js +18 -0
- package/src/cjs/index.js.map +1 -0
- package/src/cjs/package.json +3 -0
- package/src/cjs/utils.d.ts +3 -0
- package/src/cjs/utils.js +56 -0
- package/src/cjs/utils.js.map +1 -0
- package/src/esm/HttpAgent.d.ts +16 -0
- package/src/esm/HttpAgent.js +58 -0
- package/src/esm/HttpAgent.js.map +1 -0
- package/src/esm/HttpClient.d.ts +39 -0
- package/src/esm/HttpClient.js +462 -0
- package/src/esm/HttpClient.js.map +1 -0
- package/src/esm/Request.d.ts +114 -0
- package/src/esm/Request.js +2 -0
- package/src/esm/Request.js.map +1 -0
- package/src/esm/Response.d.ts +36 -0
- package/src/esm/Response.js +2 -0
- package/src/esm/Response.js.map +1 -0
- package/src/esm/index.d.ts +7 -0
- package/src/esm/index.js +13 -0
- package/src/esm/index.js.map +1 -0
- package/src/esm/package.json +3 -0
- package/src/esm/utils.d.ts +3 -0
- package/src/esm/utils.js +51 -0
- package/src/esm/utils.js.map +1 -0
- package/src/index.ts +16 -0
- package/src/utils.ts +53 -0
- package/History.md +0 -804
- package/lib/detect_proxy_agent.js +0 -31
- package/lib/get_proxy_from_uri.js +0 -81
- package/lib/httpclient.js +0 -61
- package/lib/httpclient2.js +0 -83
- package/lib/index.d.ts +0 -279
- package/lib/index.js +0 -21
- package/lib/index.test-d.ts +0 -19
- package/lib/urllib.js +0 -1317
@@ -0,0 +1,114 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
/// <reference types="node" />
|
4
|
+
/// <reference types="node" />
|
5
|
+
import { Readable, Writable } from 'stream';
|
6
|
+
import { IncomingHttpHeaders } from 'http';
|
7
|
+
import type { HttpMethod as UndiciHttpMethod } from 'undici/types/dispatcher';
|
8
|
+
import type { HttpClientResponse } from './Response';
|
9
|
+
export declare type HttpMethod = UndiciHttpMethod;
|
10
|
+
export declare type RequestURL = string | URL;
|
11
|
+
export declare type FixJSONCtlCharsHandler = (data: string) => string;
|
12
|
+
export declare type FixJSONCtlChars = boolean | FixJSONCtlCharsHandler;
|
13
|
+
export declare type RequestOptions = {
|
14
|
+
/** Request method, defaults to GET. Could be GET, POST, DELETE or PUT. Alias 'type'. */
|
15
|
+
method?: HttpMethod | Lowercase<HttpMethod>;
|
16
|
+
/** Data to be sent. Will be stringify automatically. */
|
17
|
+
data?: any;
|
18
|
+
/** Manually set the content of payload. If set, data will be ignored. */
|
19
|
+
content?: string | Buffer | Readable;
|
20
|
+
/**
|
21
|
+
* @deprecated
|
22
|
+
* Stream to be pipe to the remote. If set, data and content will be ignored.
|
23
|
+
* Alias to `content = Readable`
|
24
|
+
*/
|
25
|
+
stream?: Readable;
|
26
|
+
/**
|
27
|
+
* A writable stream to be piped by the response stream.
|
28
|
+
* Responding data will be write to this stream and callback
|
29
|
+
* will be called with data set null after finished writing.
|
30
|
+
*/
|
31
|
+
writeStream?: Writable;
|
32
|
+
/**
|
33
|
+
* The files will send with multipart/form-data format, base on formstream.
|
34
|
+
* If method not set, will use POST method by default.
|
35
|
+
*/
|
36
|
+
files?: Array<Readable | Buffer | string> | Record<string, Readable | Buffer | string> | Readable | Buffer | string;
|
37
|
+
/** Type of request data, could be 'json'. If it's 'json', will auto set Content-Type: 'application/json' header. */
|
38
|
+
contentType?: string;
|
39
|
+
/**
|
40
|
+
* Type of response data. Could be text or json.
|
41
|
+
* If it's text, the callbacked data would be a String.
|
42
|
+
* If it's json, the data of callback would be a parsed JSON Object
|
43
|
+
* and will auto set Accept: 'application/json' header.
|
44
|
+
* Default is 'buffer'.
|
45
|
+
*/
|
46
|
+
dataType?: 'text' | 'json' | 'buffer' | 'stream';
|
47
|
+
/**
|
48
|
+
* @deprecated
|
49
|
+
* Let you get the res object when request connected, default false.
|
50
|
+
* If set to true, `data` will be response readable stream.
|
51
|
+
* Alias to `dataType = 'stream'`
|
52
|
+
*/
|
53
|
+
streaming?: boolean;
|
54
|
+
/**
|
55
|
+
* @deprecated
|
56
|
+
* Alias to `dataType = 'stream'`
|
57
|
+
*/
|
58
|
+
customResponse?: boolean;
|
59
|
+
/** Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is false. */
|
60
|
+
fixJSONCtlChars?: FixJSONCtlChars;
|
61
|
+
/** Request headers. */
|
62
|
+
headers?: IncomingHttpHeaders;
|
63
|
+
/**
|
64
|
+
* Request timeout in milliseconds for connecting phase and response receiving phase.
|
65
|
+
* Defaults to exports.
|
66
|
+
* TIMEOUT, both are 5s. You can use timeout: 5000 to tell urllib use same timeout on two phase or set them seperately such as
|
67
|
+
* timeout: [3000, 5000], which will set connecting timeout to 3s and response 5s.
|
68
|
+
*/
|
69
|
+
timeout?: number | number[];
|
70
|
+
/**
|
71
|
+
* username:password used in HTTP Basic Authorization.
|
72
|
+
* Alias to `headers.authorization = xxx`
|
73
|
+
**/
|
74
|
+
auth?: string;
|
75
|
+
/** follow HTTP 3xx responses as redirects. defaults to true. */
|
76
|
+
followRedirect?: boolean;
|
77
|
+
/** The maximum number of redirects to follow, defaults to 10. */
|
78
|
+
maxRedirects?: number;
|
79
|
+
/** Format the redirect url by your self. Default is url.resolve(from, to). */
|
80
|
+
formatRedirectUrl?: (a: any, b: any) => void;
|
81
|
+
/** Before request hook, you can change every thing here. */
|
82
|
+
beforeRequest?: (...args: any[]) => void;
|
83
|
+
/** Accept `gzip, br` response content and auto decode it, default is false. */
|
84
|
+
compressed?: boolean;
|
85
|
+
/**
|
86
|
+
* @deprecated
|
87
|
+
* Alias to compressed
|
88
|
+
* */
|
89
|
+
gzip?: boolean;
|
90
|
+
/**
|
91
|
+
* @deprecated
|
92
|
+
* Enable timing or not, default is false.
|
93
|
+
* */
|
94
|
+
timing?: boolean;
|
95
|
+
/**
|
96
|
+
* Auto retry times on 5xx response, default is 0. Don't work on streaming request
|
97
|
+
* It's not supported by using retry and writeStream, because the retry request can't stop the stream which is consuming.
|
98
|
+
**/
|
99
|
+
retry?: number;
|
100
|
+
/** Wait a delay(ms) between retries */
|
101
|
+
retryDelay?: number;
|
102
|
+
/**
|
103
|
+
* Determine whether retry, a response object as the first argument.
|
104
|
+
* It will retry when status >= 500 by default. Request error is not included.
|
105
|
+
*/
|
106
|
+
isRetry?: (response: HttpClientResponse) => boolean;
|
107
|
+
/** Default: `null` */
|
108
|
+
opaque?: unknown;
|
109
|
+
/**
|
110
|
+
* @deprecated
|
111
|
+
* Maybe you should use opaque instead
|
112
|
+
*/
|
113
|
+
ctx?: unknown;
|
114
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../Request.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
import { Readable } from 'stream';
|
4
|
+
import { IncomingHttpHeaders } from 'http';
|
5
|
+
export declare type HttpClientResponseMeta = {
|
6
|
+
status: number;
|
7
|
+
statusCode: number;
|
8
|
+
headers: IncomingHttpHeaders;
|
9
|
+
size: number;
|
10
|
+
aborted: boolean;
|
11
|
+
rt: number;
|
12
|
+
keepAliveSocket: boolean;
|
13
|
+
requestUrls: string[];
|
14
|
+
/**
|
15
|
+
* https://eggjs.org/en/core/httpclient.html#timing-boolean
|
16
|
+
*/
|
17
|
+
timing: {
|
18
|
+
contentDownload: number;
|
19
|
+
waiting: number;
|
20
|
+
};
|
21
|
+
};
|
22
|
+
export declare type ReadableWithMeta = Readable & {
|
23
|
+
status: number;
|
24
|
+
statusCode: number;
|
25
|
+
headers: IncomingHttpHeaders;
|
26
|
+
};
|
27
|
+
export declare type HttpClientResponse = {
|
28
|
+
opaque: unknown;
|
29
|
+
data: any;
|
30
|
+
status: number;
|
31
|
+
headers: IncomingHttpHeaders;
|
32
|
+
url: string;
|
33
|
+
redirected: boolean;
|
34
|
+
requestUrls: string[];
|
35
|
+
res: ReadableWithMeta | HttpClientResponseMeta;
|
36
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Response.js","sourceRoot":"","sources":["../Response.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { RequestOptions, RequestURL } from './Request';
|
2
|
+
export declare function request(url: RequestURL, options?: RequestOptions): Promise<import("./Response").HttpClientResponse>;
|
3
|
+
export { HttpClient } from './HttpClient';
|
4
|
+
declare const _default: {
|
5
|
+
request: typeof request;
|
6
|
+
};
|
7
|
+
export default _default;
|
package/src/cjs/index.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.HttpClient = exports.request = void 0;
|
4
|
+
const HttpClient_1 = require("./HttpClient");
|
5
|
+
let httpclient;
|
6
|
+
async function request(url, options) {
|
7
|
+
if (!httpclient) {
|
8
|
+
httpclient = new HttpClient_1.HttpClient();
|
9
|
+
}
|
10
|
+
return await httpclient.request(url, options);
|
11
|
+
}
|
12
|
+
exports.request = request;
|
13
|
+
var HttpClient_2 = require("./HttpClient");
|
14
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return HttpClient_2.HttpClient; } });
|
15
|
+
exports.default = {
|
16
|
+
request,
|
17
|
+
};
|
18
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAG1C,IAAI,UAAsB,CAAC;AACpB,KAAK,UAAU,OAAO,CAAC,GAAe,EAAE,OAAwB;IACrE,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,IAAI,uBAAU,EAAE,CAAC;KAC/B;IACD,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AALD,0BAKC;AAED,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AAEnB,kBAAe;IACb,OAAO;CACR,CAAC"}
|
package/src/cjs/utils.js
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.sleep = exports.parseJSON = void 0;
|
4
|
+
const JSONCtlCharsMap = {
|
5
|
+
'"': '\\"',
|
6
|
+
'\\': '\\\\',
|
7
|
+
'\b': '\\b',
|
8
|
+
'\f': '\\f',
|
9
|
+
'\n': '\\n',
|
10
|
+
'\r': '\\r',
|
11
|
+
'\t': '\\t', // \u0009
|
12
|
+
};
|
13
|
+
/* eslint no-control-regex: "off"*/
|
14
|
+
const JSONCtlCharsRE = /[\u0000-\u001F\u005C]/g;
|
15
|
+
function replaceOneChar(c) {
|
16
|
+
return JSONCtlCharsMap[c] || '\\u' + (c.charCodeAt(0) + 0x10000).toString(16).substring(1);
|
17
|
+
}
|
18
|
+
function replaceJSONCtlChars(value) {
|
19
|
+
return value.replace(JSONCtlCharsRE, replaceOneChar);
|
20
|
+
}
|
21
|
+
function parseJSON(data, fixJSONCtlChars) {
|
22
|
+
if (typeof fixJSONCtlChars === 'function') {
|
23
|
+
data = fixJSONCtlChars(data);
|
24
|
+
}
|
25
|
+
else if (fixJSONCtlChars) {
|
26
|
+
// https://github.com/node-modules/urllib/pull/77
|
27
|
+
// remote the control characters (U+0000 through U+001F)
|
28
|
+
data = replaceJSONCtlChars(data);
|
29
|
+
}
|
30
|
+
try {
|
31
|
+
data = JSON.parse(data);
|
32
|
+
}
|
33
|
+
catch (err) {
|
34
|
+
if (err.name === 'SyntaxError') {
|
35
|
+
err.name = 'JSONResponseFormatError';
|
36
|
+
}
|
37
|
+
if (data.length > 1024) {
|
38
|
+
// show 0~512 ... -512~end data
|
39
|
+
err.message += ' (data json format: ' +
|
40
|
+
JSON.stringify(data.slice(0, 512)) + ' ...skip... ' + JSON.stringify(data.slice(data.length - 512)) + ')';
|
41
|
+
}
|
42
|
+
else {
|
43
|
+
err.message += ' (data json format: ' + JSON.stringify(data) + ')';
|
44
|
+
}
|
45
|
+
throw err;
|
46
|
+
}
|
47
|
+
return data;
|
48
|
+
}
|
49
|
+
exports.parseJSON = parseJSON;
|
50
|
+
function sleep(ms) {
|
51
|
+
return new Promise(resolve => {
|
52
|
+
setTimeout(resolve, ms);
|
53
|
+
});
|
54
|
+
}
|
55
|
+
exports.sleep = sleep;
|
56
|
+
//# sourceMappingURL=utils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../utils.ts"],"names":[],"mappings":";;;AAEA,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK,EAAE,SAAS;CACvB,CAAC;AACF,mCAAmC;AACnC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEhD,SAAS,cAAc,CAAC,CAAS;IAC/B,OAAO,eAAe,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC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AO,OAAO,CAAC,EAAE;QACjC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,sBAIC"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import { LookupFunction } from 'net';
|
3
|
+
import { Agent } from 'undici';
|
4
|
+
import { DispatchHandlers } from 'undici/types/dispatcher';
|
5
|
+
import { BuildOptions } from 'undici/types/connector';
|
6
|
+
export declare type CheckAddressFunction = (ip: string, family: number | string) => boolean;
|
7
|
+
export declare type HttpAgentOptions = {
|
8
|
+
lookup?: LookupFunction;
|
9
|
+
checkAddress?: CheckAddressFunction;
|
10
|
+
connect?: BuildOptions;
|
11
|
+
};
|
12
|
+
export declare class HttpAgent extends Agent {
|
13
|
+
#private;
|
14
|
+
constructor(options: HttpAgentOptions);
|
15
|
+
dispatch(options: Agent.DispatchOptions, handler: DispatchHandlers): boolean;
|
16
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
var _HttpAgent_checkAddress;
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
3
|
+
import dns from 'dns';
|
4
|
+
import { isIP } from 'net';
|
5
|
+
import { Agent, } from 'undici';
|
6
|
+
class IllegalAddressError extends Error {
|
7
|
+
constructor(hostname, ip, family) {
|
8
|
+
const message = 'illegal address';
|
9
|
+
super(message);
|
10
|
+
this.name = this.constructor.name;
|
11
|
+
this.hostname = hostname;
|
12
|
+
this.ip = ip;
|
13
|
+
this.family = family;
|
14
|
+
Error.captureStackTrace(this, this.constructor);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
export class HttpAgent extends Agent {
|
18
|
+
constructor(options) {
|
19
|
+
var _a;
|
20
|
+
/* eslint node/prefer-promises/dns: off*/
|
21
|
+
const _lookup = (_a = options.lookup) !== null && _a !== void 0 ? _a : dns.lookup;
|
22
|
+
const lookup = (hostname, dnsOptions, callback) => {
|
23
|
+
_lookup(hostname, dnsOptions, (err, address, family) => {
|
24
|
+
if (err)
|
25
|
+
return callback(err, address, family);
|
26
|
+
if (options.checkAddress && !options.checkAddress(address, family)) {
|
27
|
+
err = new IllegalAddressError(hostname, address, family);
|
28
|
+
}
|
29
|
+
callback(err, address, family);
|
30
|
+
});
|
31
|
+
};
|
32
|
+
super({
|
33
|
+
connect: { ...options.connect, lookup },
|
34
|
+
});
|
35
|
+
_HttpAgent_checkAddress.set(this, void 0);
|
36
|
+
__classPrivateFieldSet(this, _HttpAgent_checkAddress, options.checkAddress, "f");
|
37
|
+
}
|
38
|
+
dispatch(options, handler) {
|
39
|
+
if (__classPrivateFieldGet(this, _HttpAgent_checkAddress, "f") && options.origin) {
|
40
|
+
const originUrl = typeof options.origin === 'string' ? new URL(options.origin) : options.origin;
|
41
|
+
let hostname = originUrl.hostname;
|
42
|
+
// [2001:db8:2de::e13] => 2001:db8:2de::e13
|
43
|
+
if (hostname.startsWith('[') && hostname.endsWith(']')) {
|
44
|
+
hostname = hostname.substring(1, hostname.length - 1);
|
45
|
+
}
|
46
|
+
const family = isIP(hostname);
|
47
|
+
if (family === 4 || family === 6) {
|
48
|
+
// if request hostname is ip, custom lookup won't excute
|
49
|
+
if (!__classPrivateFieldGet(this, _HttpAgent_checkAddress, "f").call(this, hostname, family)) {
|
50
|
+
throw new IllegalAddressError(hostname, hostname, family);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
return super.dispatch(options, handler);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
_HttpAgent_checkAddress = new WeakMap();
|
58
|
+
//# sourceMappingURL=HttpAgent.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"HttpAgent.js","sourceRoot":"","sources":["../HttpAgent.ts"],"names":[],"mappings":";;AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAkB,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3C,OAAO,EACL,KAAK,GACN,MAAM,QAAQ,CAA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AC,CAAC;QAhBL,0CAAqC;QAiBnC,uBAAA,IAAI,2BAAiB,OAAO,CAAC,YAAY,MAAA,CAAC;IAC5C,CAAC;IAED,QAAQ,CAAC,OAA8B,EAAE,OAAyB;QAChE,IAAI,uBAAA,IAAI,+BAAc,IAAI,OAAO,CAAC,MAAM,EAAE;YACxC,MAAM,SAAS,GAAG,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;YAChG,IAAI,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;YAClC,2CAA2C;YAC3C,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBACtD,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;aACvD;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC9B,IAAI,MAAM,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,EAAE;gBAChC,wDAAwD;gBACxD,IAAI,CAAC,uBAAA,IAAI,+BAAc,MAAlB,IAAI,EAAe,QAAQ,EAAE,MAAM,CAAC,EAAE;oBACzC,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;iBAC3D;aACF;SACF;QACD,OAAO,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
/// <reference types="node" />
|
4
|
+
import { EventEmitter } from 'events';
|
5
|
+
import { LookupFunction } from 'net';
|
6
|
+
import { CheckAddressFunction } from './HttpAgent';
|
7
|
+
import { RequestURL, RequestOptions } from './Request';
|
8
|
+
import { HttpClientResponse } from './Response';
|
9
|
+
export declare type ClientOptions = {
|
10
|
+
defaultArgs?: RequestOptions;
|
11
|
+
/**
|
12
|
+
* Custom DNS lookup function, default is `dns.lookup`.
|
13
|
+
*/
|
14
|
+
lookup?: LookupFunction;
|
15
|
+
/**
|
16
|
+
* check request address to protect from SSRF and similar attacks.
|
17
|
+
* It receive two arguments(ip and family) and should return true or false to identified the address is legal or not.
|
18
|
+
* It rely on lookup and have the same version requirement.
|
19
|
+
*/
|
20
|
+
checkAddress?: CheckAddressFunction;
|
21
|
+
connect?: {
|
22
|
+
key?: string | Buffer;
|
23
|
+
/**
|
24
|
+
* A string or Buffer containing the certificate key of the client in PEM format.
|
25
|
+
* Notes: This is necessary only if using the client certificate authentication
|
26
|
+
*/
|
27
|
+
cert?: string | Buffer;
|
28
|
+
/**
|
29
|
+
* If true, the server certificate is verified against the list of supplied CAs.
|
30
|
+
* An 'error' event is emitted if verification fails.Default: true.
|
31
|
+
*/
|
32
|
+
rejectUnauthorized?: boolean;
|
33
|
+
};
|
34
|
+
};
|
35
|
+
export declare class HttpClient extends EventEmitter {
|
36
|
+
#private;
|
37
|
+
constructor(clientOptions?: ClientOptions);
|
38
|
+
request(url: RequestURL, options?: RequestOptions): Promise<HttpClientResponse>;
|
39
|
+
}
|