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.
Files changed (55) hide show
  1. package/README.md +75 -264
  2. package/package.json +62 -59
  3. package/src/HttpAgent.ts +72 -0
  4. package/src/HttpClient.ts +514 -0
  5. package/src/Request.ts +118 -0
  6. package/src/Response.ts +41 -0
  7. package/src/cjs/HttpAgent.d.ts +16 -0
  8. package/src/cjs/HttpAgent.js +62 -0
  9. package/src/cjs/HttpAgent.js.map +1 -0
  10. package/src/cjs/HttpClient.d.ts +39 -0
  11. package/src/cjs/HttpClient.js +466 -0
  12. package/src/cjs/HttpClient.js.map +1 -0
  13. package/src/cjs/Request.d.ts +114 -0
  14. package/src/cjs/Request.js +3 -0
  15. package/src/cjs/Request.js.map +1 -0
  16. package/src/cjs/Response.d.ts +36 -0
  17. package/src/cjs/Response.js +3 -0
  18. package/src/cjs/Response.js.map +1 -0
  19. package/src/cjs/index.d.ts +7 -0
  20. package/src/cjs/index.js +18 -0
  21. package/src/cjs/index.js.map +1 -0
  22. package/src/cjs/package.json +3 -0
  23. package/src/cjs/utils.d.ts +3 -0
  24. package/src/cjs/utils.js +56 -0
  25. package/src/cjs/utils.js.map +1 -0
  26. package/src/esm/HttpAgent.d.ts +16 -0
  27. package/src/esm/HttpAgent.js +58 -0
  28. package/src/esm/HttpAgent.js.map +1 -0
  29. package/src/esm/HttpClient.d.ts +39 -0
  30. package/src/esm/HttpClient.js +462 -0
  31. package/src/esm/HttpClient.js.map +1 -0
  32. package/src/esm/Request.d.ts +114 -0
  33. package/src/esm/Request.js +2 -0
  34. package/src/esm/Request.js.map +1 -0
  35. package/src/esm/Response.d.ts +36 -0
  36. package/src/esm/Response.js +2 -0
  37. package/src/esm/Response.js.map +1 -0
  38. package/src/esm/index.d.ts +7 -0
  39. package/src/esm/index.js +13 -0
  40. package/src/esm/index.js.map +1 -0
  41. package/src/esm/package.json +3 -0
  42. package/src/esm/utils.d.ts +3 -0
  43. package/src/esm/utils.js +51 -0
  44. package/src/esm/utils.js.map +1 -0
  45. package/src/index.ts +16 -0
  46. package/src/utils.ts +53 -0
  47. package/History.md +0 -804
  48. package/lib/detect_proxy_agent.js +0 -31
  49. package/lib/get_proxy_from_uri.js +0 -81
  50. package/lib/httpclient.js +0 -61
  51. package/lib/httpclient2.js +0 -83
  52. package/lib/index.d.ts +0 -279
  53. package/lib/index.js +0 -21
  54. package/lib/index.test-d.ts +0 -19
  55. package/lib/urllib.js +0 -1317
@@ -1,31 +0,0 @@
1
- 'use strict';
2
-
3
- var debug = require('debug')('urllib:detect_proxy_agent');
4
- var getProxyFromURI = require('./get_proxy_from_uri');
5
-
6
- var proxyAgents = {};
7
-
8
- function detectProxyAgent(uri, args) {
9
- if (!args.enableProxy && !process.env.URLLIB_ENABLE_PROXY) {
10
- return null;
11
- }
12
- var proxy = args.proxy || process.env.URLLIB_PROXY;
13
- if (!proxy) {
14
- proxy = getProxyFromURI(uri);
15
- if (!proxy) {
16
- return null;
17
- }
18
- }
19
-
20
- var proxyAgent = proxyAgents[proxy];
21
- if (!proxyAgent) {
22
- debug('create new proxy %s', proxy);
23
- // lazy require, only support node >= 4
24
- proxyAgent = proxyAgents[proxy] = new (require('proxy-agent'))(proxy);
25
- }
26
- debug('get proxy: %s', proxy);
27
- return proxyAgent;
28
- }
29
-
30
- module.exports = detectProxyAgent;
31
- module.exports.proxyAgents = proxyAgents;
@@ -1,81 +0,0 @@
1
- // copy from https://github.com/request/request/blob/90cf8c743bb9fd6a4cb683a56fb7844c6b316866/lib/getProxyFromURI.js
2
-
3
- 'use strict'
4
-
5
- function formatHostname(hostname) {
6
- // canonicalize the hostname, so that 'oogle.com' won't match 'google.com'
7
- return hostname.replace(/^\.*/, '.').toLowerCase()
8
- }
9
-
10
- function parseNoProxyZone(zone) {
11
- zone = zone.trim().toLowerCase()
12
-
13
- var zoneParts = zone.split(':', 2)
14
- , zoneHost = formatHostname(zoneParts[0])
15
- , zonePort = zoneParts[1]
16
- , hasPort = zone.indexOf(':') > -1
17
-
18
- return {hostname: zoneHost, port: zonePort, hasPort: hasPort}
19
- }
20
-
21
- function uriInNoProxy(uri, noProxy) {
22
- var port = uri.port || (uri.protocol === 'https:' ? '443' : '80')
23
- , hostname = formatHostname(uri.hostname)
24
- , noProxyList = noProxy.split(',')
25
-
26
- // iterate through the noProxyList until it finds a match.
27
- return noProxyList.map(parseNoProxyZone).some(function(noProxyZone) {
28
- var isMatchedAt = hostname.indexOf(noProxyZone.hostname)
29
- , hostnameMatched = (
30
- isMatchedAt > -1 &&
31
- (isMatchedAt === hostname.length - noProxyZone.hostname.length)
32
- )
33
-
34
- if (noProxyZone.hasPort) {
35
- return (port === noProxyZone.port) && hostnameMatched
36
- }
37
-
38
- return hostnameMatched
39
- })
40
- }
41
-
42
- function getProxyFromURI(uri) {
43
- // Decide the proper request proxy to use based on the request URI object and the
44
- // environmental variables (NO_PROXY, HTTP_PROXY, etc.)
45
- // respect NO_PROXY environment variables (see: http://lynx.isc.org/current/breakout/lynx_help/keystrokes/environments.html)
46
-
47
- var noProxy = process.env.NO_PROXY || process.env.no_proxy || ''
48
-
49
- // if the noProxy is a wildcard then return null
50
-
51
- if (noProxy === '*') {
52
- return null
53
- }
54
-
55
- // if the noProxy is not empty and the uri is found return null
56
-
57
- if (noProxy !== '' && uriInNoProxy(uri, noProxy)) {
58
- return null
59
- }
60
-
61
- // Check for HTTP or HTTPS Proxy in environment Else default to null
62
-
63
- if (uri.protocol === 'http:') {
64
- return process.env.HTTP_PROXY ||
65
- process.env.http_proxy || null
66
- }
67
-
68
- if (uri.protocol === 'https:') {
69
- return process.env.HTTPS_PROXY ||
70
- process.env.https_proxy ||
71
- process.env.HTTP_PROXY ||
72
- process.env.http_proxy || null
73
- }
74
-
75
- // if none of that works, return null
76
- // (What uri protocol are you using then?)
77
-
78
- return null
79
- }
80
-
81
- module.exports = getProxyFromURI
package/lib/httpclient.js DELETED
@@ -1,61 +0,0 @@
1
- 'use strict';
2
-
3
- var EventEmitter = require('events').EventEmitter;
4
- var util = require('util');
5
- var utility = require('utility');
6
- var urllib = require('./urllib');
7
-
8
- module.exports = HttpClient;
9
-
10
- function HttpClient(options) {
11
- EventEmitter.call(this);
12
- options = options || {};
13
-
14
- if (options.agent !== undefined) {
15
- this.agent = options.agent;
16
- this.hasCustomAgent = true;
17
- } else {
18
- this.agent = urllib.agent;
19
- this.hasCustomAgent = false;
20
- }
21
-
22
- if (options.httpsAgent !== undefined) {
23
- this.httpsAgent = options.httpsAgent;
24
- this.hasCustomHttpsAgent = true;
25
- } else {
26
- this.httpsAgent = urllib.httpsAgent;
27
- this.hasCustomHttpsAgent = false;
28
- }
29
- this.defaultArgs = options.defaultArgs;
30
- }
31
- util.inherits(HttpClient, EventEmitter);
32
-
33
- HttpClient.prototype.request = HttpClient.prototype.curl = function (url, args, callback) {
34
- if (typeof args === 'function') {
35
- callback = args;
36
- args = null;
37
- }
38
- args = args || {};
39
- if (this.defaultArgs) {
40
- args = utility.assign({}, [ this.defaultArgs, args ]);
41
- }
42
- args.emitter = this;
43
- args.agent = getAgent(args.agent, this.agent);
44
- args.httpsAgent = getAgent(args.httpsAgent, this.httpsAgent);
45
- return urllib.request(url, args, callback);
46
- };
47
-
48
- HttpClient.prototype.requestThunk = function (url, args) {
49
- args = args || {};
50
- if (this.defaultArgs) {
51
- args = utility.assign({}, [ this.defaultArgs, args ]);
52
- }
53
- args.emitter = this;
54
- args.agent = getAgent(args.agent, this.agent);
55
- args.httpsAgent = getAgent(args.httpsAgent, this.httpsAgent);
56
- return urllib.requestThunk(url, args);
57
- };
58
-
59
- function getAgent(agent, defaultAgent) {
60
- return agent === undefined ? defaultAgent : agent;
61
- }
@@ -1,83 +0,0 @@
1
- 'use strict';
2
-
3
- var util = require('util');
4
- var debug = require('debug')('urllib');
5
- var ms = require('humanize-ms');
6
- var HttpClient = require('./httpclient');
7
-
8
- var _Promise;
9
-
10
- module.exports = HttpClient2;
11
-
12
- function HttpClient2(options) {
13
- HttpClient.call(this, options);
14
- }
15
-
16
- util.inherits(HttpClient2, HttpClient);
17
-
18
- HttpClient2.prototype.request = HttpClient2.prototype.curl = function request(url, args) {
19
- var self = this;
20
- args = args || {};
21
- args.retry = args.retry || 0;
22
- if (args.retryDelay) {
23
- args.retryDelay = ms(args.retryDelay);
24
- }
25
- args.isRetry = args.isRetry || function(res) {
26
- return res.status >= 500;
27
- };
28
- return HttpClient.prototype.request.call(self, url, args)
29
- .then(function(res) {
30
- if (args.retry > 0 && typeof args.isRetry === 'function' && args.isRetry(res)) {
31
- args.retry--;
32
- debug('retry request %s, remain %s', url, args.retry);
33
- if (args.retryDelay) {
34
- debug('retry after %sms', args.retryDelay);
35
- return sleep(args.retryDelay).then(function() { return self.request(url, args); });
36
- }
37
- return self.request(url, args);
38
- }
39
- return res;
40
- })
41
- .catch(function(err) {
42
- if (args.retry > 0) {
43
- args.retry--;
44
- debug('retry request %s, remain %s, err %s', url, args.retry, err);
45
- if (args.retryDelay) {
46
- debug('retry after %sms', args.retryDelay);
47
- return sleep(args.retryDelay).then(function() { return self.request(url, args); });
48
- }
49
- return self.request(url, args);
50
- }
51
- throw err;
52
- });
53
- };
54
-
55
- HttpClient2.prototype.requestThunk = function requestThunk(url, args) {
56
- var self = this;
57
- return function(callback) {
58
- self.request(url, args)
59
- .then(function(res) {
60
- var cb = callback;
61
- // make sure cb(null, res) throw error won't emit catch callback below
62
- callback = null;
63
- cb(null, res);
64
- })
65
- .catch(function(err) {
66
- if (!callback) {
67
- // TODO: how to handle this error?
68
- return;
69
- }
70
- callback(err);
71
- });
72
- };
73
- };
74
-
75
- function sleep(ms) {
76
- if (!_Promise) {
77
- _Promise = require('any-promise');
78
- }
79
-
80
- return new _Promise(function(resolve) {
81
- setTimeout(resolve, ms);
82
- });
83
- }
package/lib/index.d.ts DELETED
@@ -1,279 +0,0 @@
1
- import * as https from 'https';
2
- import * as http from 'http';
3
- import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
4
- import * as url from 'url';
5
- import { Readable, Writable } from 'stream';
6
- import { EventEmitter } from 'events';
7
- import { LookupFunction } from 'net';
8
-
9
- export { IncomingHttpHeaders, OutgoingHttpHeaders };
10
- export type HttpMethod = "GET" | "POST" | "DELETE" | "PUT" | "HEAD" | "OPTIONS" | "PATCH" | "TRACE" | "CONNECT";
11
-
12
- export as namespace urllib;
13
- export interface RequestOptions {
14
- /** Request method, defaults to GET. Could be GET, POST, DELETE or PUT. Alias 'type'. */
15
- method?: HttpMethod;
16
- /** Alias method */
17
- type?: HttpMethod;
18
- /** Data to be sent. Will be stringify automatically. */
19
- data?: any;
20
- /** Force convert data to query string. */
21
- dataAsQueryString?: boolean;
22
- /** Manually set the content of payload. If set, data will be ignored. */
23
- content?: string | Buffer;
24
- /** Stream to be pipe to the remote.If set, data and content will be ignored. */
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
- /** consume the writeStream, invoke the callback after writeStream close. */
33
- consumeWriteStream?: boolean;
34
- /**
35
- * The files will send with multipart/form-data format, base on formstream.
36
- * If method not set, will use POST method by default.
37
- */
38
- files?: Array<Readable | Buffer | string> | object | Readable | Buffer | string;
39
- /** Type of request data.Could be json.If it's json, will auto set Content-Type: application/json header. */
40
- contentType?: string;
41
- /**
42
- * urllib default use querystring to stringify form data which don't support nested object,
43
- * will use qs instead of querystring to support nested object by set this option to true.
44
- */
45
- nestedQuerystring?: boolean;
46
- /**
47
- * Type of response data. Could be text or json.
48
- * If it's text, the callbacked data would be a String.
49
- * If it's json, the data of callback would be a parsed JSON Object
50
- * and will auto set Accept: application/json header. Default callbacked data would be a Buffer.
51
- */
52
- dataType?: string;
53
- /** Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is false. */
54
- fixJSONCtlChars?: boolean;
55
- /** Request headers. */
56
- headers?: IncomingHttpHeaders;
57
- /** by default will convert header keys to lowercase */
58
- keepHeaderCase?: boolean;
59
- /**
60
- * Request timeout in milliseconds for connecting phase and response receiving phase.
61
- * Defaults to exports.
62
- * TIMEOUT, both are 5s.You can use timeout: 5000 to tell urllib use same timeout on two phase or set them seperately such as
63
- * timeout: [3000, 5000], which will set connecting timeout to 3s and response 5s.
64
- */
65
- timeout?: number | number[];
66
- /** username:password used in HTTP Basic Authorization. */
67
- auth?: string;
68
- /** username:password used in HTTP Digest Authorization. */
69
- digestAuth?: string;
70
- /** HTTP Agent object.Set false if you does not use agent. */
71
- agent?: http.Agent;
72
- /** HTTPS Agent object. Set false if you does not use agent. */
73
- httpsAgent?: https.Agent;
74
- /**
75
- * An array of strings or Buffers of trusted certificates.
76
- * If this is omitted several well known "root" CAs will be used, like VeriSign.
77
- * These are used to authorize connections.
78
- * Notes: This is necessary only if the server uses the self - signed certificate
79
- */
80
- ca?: string | Buffer | string[] | Buffer[];
81
- /**
82
- * If true, the server certificate is verified against the list of supplied CAs.
83
- * An 'error' event is emitted if verification fails.Default: true.
84
- */
85
- rejectUnauthorized?: boolean;
86
- /** A string or Buffer containing the private key, certificate and CA certs of the server in PFX or PKCS12 format. */
87
- pfx?: string | Buffer;
88
- /**
89
- * A string or Buffer containing the private key of the client in PEM format.
90
- * Notes: This is necessary only if using the client certificate authentication
91
- */
92
- key?: string | Buffer;
93
- /**
94
- * A string or Buffer containing the certificate key of the client in PEM format.
95
- * Notes: This is necessary only if using the client certificate authentication
96
- */
97
- cert?: string | Buffer;
98
- /** A string of passphrase for the private key or pfx. */
99
- passphrase?: string;
100
- /** A string describing the ciphers to use or exclude. */
101
- ciphers?: string;
102
- /** The SSL method to use, e.g.SSLv3_method to force SSL version 3. */
103
- secureProtocol?: string;
104
- /** follow HTTP 3xx responses as redirects. defaults to false. */
105
- followRedirect?: boolean;
106
- /** The maximum number of redirects to follow, defaults to 10. */
107
- maxRedirects?: number;
108
- /** Format the redirect url by your self. Default is url.resolve(from, to). */
109
- formatRedirectUrl?: (a: any, b: any) => void;
110
- /** Before request hook, you can change every thing here. */
111
- beforeRequest?: (...args: any[]) => void;
112
- /** let you get the res object when request connected, default false. alias customResponse */
113
- streaming?: boolean;
114
- /** Accept gzip response content and auto decode it, default is false. */
115
- gzip?: boolean;
116
- /** Enable timing or not, default is false. */
117
- timing?: boolean;
118
- /** Enable proxy request, default is false. */
119
- enableProxy?: boolean;
120
- /** proxy agent uri or options, default is null. */
121
- proxy?: string | { [key: string]: any };
122
- /**
123
- * Custom DNS lookup function, default is dns.lookup.
124
- * Require node >= 4.0.0(for http protocol) and node >=8(for https protocol)
125
- */
126
- lookup?: LookupFunction;
127
- /**
128
- * check request address to protect from SSRF and similar attacks.
129
- * It receive two arguments(ip and family) and should return true or false to identified the address is legal or not.
130
- * It rely on lookup and have the same version requirement.
131
- */
132
- checkAddress?: (ip: string, family: number | string) => boolean;
133
- /**
134
- * UNIX domain socket path. (Windows is not supported)
135
- */
136
- socketPath?: string;
137
- }
138
-
139
- export interface HttpClientResponse<T> {
140
- data: T;
141
- status: number;
142
- headers: OutgoingHttpHeaders;
143
- res: http.IncomingMessage & {
144
- /**
145
- * https://eggjs.org/en/core/httpclient.html#timing-boolean
146
- */
147
- timing?: {
148
- queuing: number;
149
- dnslookup: number;
150
- connected: number;
151
- requestSent: number;
152
- waiting: number;
153
- contentDownload: number;
154
- }
155
- };
156
- }
157
-
158
-
159
- /**
160
- * @param data Outgoing message
161
- * @param res http response
162
- */
163
- export type Callback<T> = (err: Error, data: T, res: http.IncomingMessage) => void;
164
-
165
- /**
166
- * Handle all http request, both http and https support well.
167
- *
168
- * @example
169
- * // GET http://httptest.cnodejs.net
170
- * urllib.request('http://httptest.cnodejs.net/test/get', function(err, data, res) {});
171
- * // POST http://httptest.cnodejs.net
172
- * var args = { type: 'post', data: { foo: 'bar' } };
173
- * urllib.request('http://httptest.cnodejs.net/test/post', args, function(err, data, res) {});
174
- *
175
- * @param url The URL to request, either a String or a Object that return by url.parse.
176
- */
177
- export function request<T = any>(url: string | url.URL, options?: RequestOptions): Promise<HttpClientResponse<T>>;
178
- /**
179
- * @param url The URL to request, either a String or a Object that return by url.parse.
180
- */
181
- export function request<T = any>(url: string | url.URL, callback: Callback<T>): void;
182
- /**
183
- * @param url The URL to request, either a String or a Object that return by url.parse.
184
- */
185
- export function request<T = any>(url: string | url.URL, options: RequestOptions, callback: Callback<T>): void;
186
-
187
- /**
188
- * Handle request with a callback.
189
- * @param url The URL to request, either a String or a Object that return by url.parse.
190
- */
191
- export function requestWithCallback<T = any>(url: string | url.URL, callback: Callback<T>): void;
192
- /**
193
- * @param url The URL to request, either a String or a Object that return by url.parse.
194
- */
195
- export function requestWithCallback<T = any>(url: string | url.URL, options: RequestOptions, callback: Callback<T>): void;
196
-
197
- /**
198
- * yield urllib.requestThunk(url, args)
199
- * @param url The URL to request, either a String or a Object that return by url.parse.
200
- */
201
- export function requestThunk<T = any>(url: string | url.URL, options?: RequestOptions): (callback: Callback<T>) => void;
202
-
203
- /**
204
- * alias to request.
205
- * Handle all http request, both http and https support well.
206
- *
207
- * @example
208
- * // GET http://httptest.cnodejs.net
209
- * urllib.request('http://httptest.cnodejs.net/test/get', function(err, data, res) {});
210
- * // POST http://httptest.cnodejs.net
211
- * var args = { type: 'post', data: { foo: 'bar' } };
212
- * urllib.request('http://httptest.cnodejs.net/test/post', args, function(err, data, res) {});
213
- *
214
- * @param url The URL to request, either a String or a Object that return by url.parse.
215
- * @param options Optional, @see RequestOptions.
216
- */
217
- export function curl<T = any>(url: string | url.URL, options?: RequestOptions): Promise<HttpClientResponse<T>>;
218
- /**
219
- * @param url The URL to request, either a String or a Object that return by url.parse.
220
- */
221
- export function curl<T = any>(url: string | url.URL, callback: Callback<T>): void;
222
- /**
223
- * @param url The URL to request, either a String or a Object that return by url.parse.
224
- */
225
- export function curl<T = any>(url: string | url.URL, options: RequestOptions, callback: Callback<T>): void;
226
- /**
227
- * The default request timeout(in milliseconds).
228
- */
229
- export const TIMEOUT: number;
230
- /**
231
- * The default request & response timeout(in milliseconds).
232
- */
233
- export const TIMEOUTS: [number, number];
234
-
235
- /**
236
- * Request user agent.
237
- */
238
- export const USER_AGENT: string;
239
-
240
- /**
241
- * Request http agent.
242
- */
243
- export const agent: http.Agent;
244
-
245
- /**
246
- * Request https agent.
247
- */
248
- export const httpsAgent: https.Agent;
249
-
250
- export class HttpClient<O extends RequestOptions = RequestOptions> extends EventEmitter {
251
- request<T = any>(url: string | url.URL): Promise<HttpClientResponse<T>>;
252
- request<T = any>(url: string | url.URL, options: O): Promise<HttpClientResponse<T>>;
253
- request<T = any>(url: string | url.URL, callback: Callback<T>): void;
254
- request<T = any>(url: string | url.URL, options: O, callback: Callback<T>): void;
255
-
256
- curl<T = any>(url: string | url.URL, options: O): Promise<HttpClientResponse<T>>;
257
- curl<T = any>(url: string | url.URL): Promise<HttpClientResponse<T>>;
258
- curl<T = any>(url: string | url.URL, callback: Callback<T>): void;
259
- curl<T = any>(url: string | url.URL, options: O, callback: Callback<T>): void;
260
-
261
- requestThunk(url: string | url.URL, options?: O): (callback: (...args: any[]) => void) => void;
262
- }
263
-
264
- export interface RequestOptions2 extends RequestOptions {
265
- retry?: number;
266
- retryDelay?: number;
267
- isRetry?: (res: HttpClientResponse<any>) => boolean;
268
- }
269
-
270
- /**
271
- * request method only return a promise,
272
- * compatible with async/await and generator in co.
273
- */
274
- export class HttpClient2 extends HttpClient<RequestOptions2> {}
275
-
276
- /**
277
- * Create a HttpClient instance.
278
- */
279
- export function create(options?: RequestOptions): HttpClient;
package/lib/index.js DELETED
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- var urllib = require('./urllib');
4
-
5
- exports.USER_AGENT = urllib.USER_AGENT;
6
- exports.TIMEOUT = urllib.TIMEOUT;
7
- exports.TIMEOUTS = urllib.TIMEOUTS;
8
- exports.agent = urllib.agent;
9
- exports.httpsAgent = urllib.httpsAgent;
10
-
11
- exports.curl = urllib.curl;
12
- exports.request = urllib.request;
13
- exports.requestWithCallback = urllib.requestWithCallback;
14
- exports.requestThunk = urllib.requestThunk;
15
-
16
- exports.HttpClient = require('./httpclient');
17
- exports.HttpClient2 = require('./httpclient2');
18
-
19
- exports.create = function (options) {
20
- return new exports.HttpClient(options);
21
- };
@@ -1,19 +0,0 @@
1
- import { expectType } from 'tsd';
2
- import { curl } from '..';
3
-
4
- // curl
5
- expectType<Buffer>((await curl<Buffer>('http://a.com')).data);
6
- // RequestOptions
7
- expectType<Buffer>((await curl<Buffer>('http://a.com', {})).data);
8
- expectType<string>((await curl<string>('http://a.com', {
9
- method: 'HEAD',
10
- })).data);
11
-
12
- // HttpClientResponse
13
- const res = await curl<Buffer>('http://a.com');
14
- expectType<number | undefined>(res.res.timing?.queuing);
15
- expectType<number | undefined>(res.res.timing?.dnslookup);
16
- expectType<number | undefined>(res.res.timing?.connected);
17
- expectType<number | undefined>(res.res.timing?.requestSent);
18
- expectType<number | undefined>(res.res.timing?.waiting);
19
- expectType<number | undefined>(res.res.timing?.contentDownload);