got 12.0.0-beta.2 → 12.0.1
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/dist/source/as-promise/index.d.ts +1 -1
- package/dist/source/as-promise/index.js +5 -9
- package/dist/source/as-promise/types.d.ts +19 -0
- package/dist/source/as-promise/types.js +3 -0
- package/dist/source/core/errors.js +1 -0
- package/dist/source/core/index.d.ts +6 -6
- package/dist/source/core/index.js +30 -6
- package/dist/source/core/options.d.ts +186 -66
- package/dist/source/core/options.js +90 -21
- package/dist/source/core/response.d.ts +2 -1
- package/dist/source/core/response.js +4 -4
- package/dist/source/core/timed-out.d.ts +1 -1
- package/dist/source/core/timed-out.js +1 -1
- package/dist/source/core/utils/get-body-size.d.ts +1 -1
- package/dist/source/core/utils/get-body-size.js +2 -1
- package/dist/source/core/utils/is-client-request.d.ts +2 -2
- package/dist/source/core/utils/is-form-data.d.ts +1 -1
- package/dist/source/core/utils/options-to-url.d.ts +1 -1
- package/dist/source/core/utils/options-to-url.js +1 -1
- package/dist/source/core/utils/proxy-events.d.ts +1 -1
- package/dist/source/core/utils/unhandle.d.ts +1 -1
- package/dist/source/core/utils/url-to-options.d.ts +1 -1
- package/dist/source/index.d.ts +1 -0
- package/dist/source/types.d.ts +2 -1
- package/package.json +32 -26
- package/readme.md +92 -73
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { promisify, inspect } from 'node:util';
|
|
3
|
+
import { URL, URLSearchParams } from 'node:url';
|
|
4
|
+
import { checkServerIdentity } from 'node:tls';
|
|
5
|
+
// DO NOT use destructuring for `https.request` and `http.request` as it's not compatible with `nock`.
|
|
6
|
+
import http from 'node:http';
|
|
7
|
+
import https from 'node:https';
|
|
6
8
|
import is, { assert } from '@sindresorhus/is';
|
|
7
9
|
import lowercaseKeys from 'lowercase-keys';
|
|
8
10
|
import CacheableLookup from 'cacheable-lookup';
|
|
9
11
|
import http2wrapper from 'http2-wrapper';
|
|
12
|
+
import { isFormDataLike } from 'form-data-encoder';
|
|
10
13
|
import parseLinkHeader from './parse-link-header.js';
|
|
11
14
|
const [major, minor] = process.versions.node.split('.').map(v => Number(v));
|
|
12
15
|
function validateSearchParameters(searchParameters) {
|
|
@@ -210,6 +213,71 @@ const cloneInternals = (internals) => {
|
|
|
210
213
|
}
|
|
211
214
|
return result;
|
|
212
215
|
};
|
|
216
|
+
const cloneRaw = (raw) => {
|
|
217
|
+
const { hooks, retry } = raw;
|
|
218
|
+
const result = { ...raw };
|
|
219
|
+
if (is.object(raw.context)) {
|
|
220
|
+
result.context = { ...raw.context };
|
|
221
|
+
}
|
|
222
|
+
if (is.object(raw.cacheOptions)) {
|
|
223
|
+
result.cacheOptions = { ...raw.cacheOptions };
|
|
224
|
+
}
|
|
225
|
+
if (is.object(raw.https)) {
|
|
226
|
+
result.https = { ...raw.https };
|
|
227
|
+
}
|
|
228
|
+
if (is.object(raw.cacheOptions)) {
|
|
229
|
+
result.cacheOptions = { ...result.cacheOptions };
|
|
230
|
+
}
|
|
231
|
+
if (is.object(raw.agent)) {
|
|
232
|
+
result.agent = { ...raw.agent };
|
|
233
|
+
}
|
|
234
|
+
if (is.object(raw.headers)) {
|
|
235
|
+
result.headers = { ...raw.headers };
|
|
236
|
+
}
|
|
237
|
+
if (is.object(retry)) {
|
|
238
|
+
result.retry = { ...retry };
|
|
239
|
+
if (is.array(retry.errorCodes)) {
|
|
240
|
+
result.retry.errorCodes = [...retry.errorCodes];
|
|
241
|
+
}
|
|
242
|
+
if (is.array(retry.methods)) {
|
|
243
|
+
result.retry.methods = [...retry.methods];
|
|
244
|
+
}
|
|
245
|
+
if (is.array(retry.statusCodes)) {
|
|
246
|
+
result.retry.statusCodes = [...retry.statusCodes];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (is.object(raw.timeout)) {
|
|
250
|
+
result.timeout = { ...raw.timeout };
|
|
251
|
+
}
|
|
252
|
+
if (is.object(hooks)) {
|
|
253
|
+
result.hooks = {
|
|
254
|
+
...hooks,
|
|
255
|
+
};
|
|
256
|
+
if (is.array(hooks.init)) {
|
|
257
|
+
result.hooks.init = [...hooks.init];
|
|
258
|
+
}
|
|
259
|
+
if (is.array(hooks.beforeRequest)) {
|
|
260
|
+
result.hooks.beforeRequest = [...hooks.beforeRequest];
|
|
261
|
+
}
|
|
262
|
+
if (is.array(hooks.beforeError)) {
|
|
263
|
+
result.hooks.beforeError = [...hooks.beforeError];
|
|
264
|
+
}
|
|
265
|
+
if (is.array(hooks.beforeRedirect)) {
|
|
266
|
+
result.hooks.beforeRedirect = [...hooks.beforeRedirect];
|
|
267
|
+
}
|
|
268
|
+
if (is.array(hooks.beforeRetry)) {
|
|
269
|
+
result.hooks.beforeRetry = [...hooks.beforeRetry];
|
|
270
|
+
}
|
|
271
|
+
if (is.array(hooks.afterResponse)) {
|
|
272
|
+
result.hooks.afterResponse = [...hooks.afterResponse];
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// TODO: raw.searchParams
|
|
276
|
+
if (is.object(raw.pagination)) {
|
|
277
|
+
result.pagination = { ...raw.pagination };
|
|
278
|
+
}
|
|
279
|
+
return result;
|
|
280
|
+
};
|
|
213
281
|
const getHttp2TimeoutOption = (internals) => {
|
|
214
282
|
const delays = [internals.timeout.socket, internals.timeout.connect, internals.timeout.lookup, internals.timeout.request, internals.timeout.secureConnect].filter(delay => typeof delay === 'number');
|
|
215
283
|
if (delays.length > 0) {
|
|
@@ -315,19 +383,9 @@ export default class Options {
|
|
|
315
383
|
}
|
|
316
384
|
return;
|
|
317
385
|
}
|
|
386
|
+
options = cloneRaw(options);
|
|
318
387
|
init(this, options, this);
|
|
319
388
|
init(options, options, this);
|
|
320
|
-
// This is way much faster than cloning ^_^
|
|
321
|
-
Object.freeze(options);
|
|
322
|
-
Object.freeze(options.hooks);
|
|
323
|
-
Object.freeze(options.https);
|
|
324
|
-
Object.freeze(options.cacheOptions);
|
|
325
|
-
Object.freeze(options.agent);
|
|
326
|
-
Object.freeze(options.headers);
|
|
327
|
-
Object.freeze(options.timeout);
|
|
328
|
-
Object.freeze(options.retry);
|
|
329
|
-
Object.freeze(options.hooks);
|
|
330
|
-
Object.freeze(options.context);
|
|
331
389
|
this._merging = true;
|
|
332
390
|
// Always merge `isStream` first
|
|
333
391
|
if ('isStream' in options) {
|
|
@@ -541,7 +599,7 @@ export default class Options {
|
|
|
541
599
|
|
|
542
600
|
__Note #4__: This option is not enumerable and will not be merged with the instance defaults.
|
|
543
601
|
|
|
544
|
-
The `content-length` header will be automatically set if `body` is a `string` / `Buffer` / [`form-data` instance](https://github.com/form-data/form-data), and `content-length` and `transfer-encoding` are not manually set in `options.headers`.
|
|
602
|
+
The `content-length` header will be automatically set if `body` is a `string` / `Buffer` / [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) / [`form-data` instance](https://github.com/form-data/form-data), and `content-length` and `transfer-encoding` are not manually set in `options.headers`.
|
|
545
603
|
|
|
546
604
|
Since Got 12, the `content-length` is not automatically set when `body` is a `fs.createReadStream`.
|
|
547
605
|
*/
|
|
@@ -549,7 +607,7 @@ export default class Options {
|
|
|
549
607
|
return this._internals.body;
|
|
550
608
|
}
|
|
551
609
|
set body(value) {
|
|
552
|
-
assert.any([is.string, is.buffer, is.nodeStream, is.generator, is.asyncGenerator, is.undefined], value);
|
|
610
|
+
assert.any([is.string, is.buffer, is.nodeStream, is.generator, is.asyncGenerator, isFormDataLike, is.undefined], value);
|
|
553
611
|
if (is.nodeStream(value)) {
|
|
554
612
|
assert.truthy(value.readable);
|
|
555
613
|
}
|
|
@@ -1441,6 +1499,7 @@ export default class Options {
|
|
|
1441
1499
|
assert.any([is.number, is.undefined], value);
|
|
1442
1500
|
this._internals.maxHeaderSize = value;
|
|
1443
1501
|
}
|
|
1502
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1444
1503
|
toJSON() {
|
|
1445
1504
|
return { ...this._internals };
|
|
1446
1505
|
}
|
|
@@ -1469,6 +1528,8 @@ export default class Options {
|
|
|
1469
1528
|
...internals.cacheOptions,
|
|
1470
1529
|
...this._unixOptions,
|
|
1471
1530
|
// HTTPS options
|
|
1531
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1532
|
+
ALPNProtocols: https.alpnProtocols,
|
|
1472
1533
|
ca: https.certificateAuthority,
|
|
1473
1534
|
cert: https.certificate,
|
|
1474
1535
|
key: https.key,
|
|
@@ -1522,21 +1583,29 @@ export default class Options {
|
|
|
1522
1583
|
}
|
|
1523
1584
|
return http2wrapper.auto;
|
|
1524
1585
|
}
|
|
1525
|
-
return
|
|
1586
|
+
return https.request;
|
|
1526
1587
|
}
|
|
1527
|
-
return
|
|
1588
|
+
return http.request;
|
|
1528
1589
|
}
|
|
1529
1590
|
freeze() {
|
|
1530
1591
|
const options = this._internals;
|
|
1531
1592
|
Object.freeze(options);
|
|
1532
1593
|
Object.freeze(options.hooks);
|
|
1594
|
+
Object.freeze(options.hooks.afterResponse);
|
|
1595
|
+
Object.freeze(options.hooks.beforeError);
|
|
1596
|
+
Object.freeze(options.hooks.beforeRedirect);
|
|
1597
|
+
Object.freeze(options.hooks.beforeRequest);
|
|
1598
|
+
Object.freeze(options.hooks.beforeRetry);
|
|
1599
|
+
Object.freeze(options.hooks.init);
|
|
1533
1600
|
Object.freeze(options.https);
|
|
1534
1601
|
Object.freeze(options.cacheOptions);
|
|
1535
1602
|
Object.freeze(options.agent);
|
|
1536
1603
|
Object.freeze(options.headers);
|
|
1537
1604
|
Object.freeze(options.timeout);
|
|
1538
1605
|
Object.freeze(options.retry);
|
|
1539
|
-
Object.freeze(options.
|
|
1606
|
+
Object.freeze(options.retry.errorCodes);
|
|
1607
|
+
Object.freeze(options.retry.methods);
|
|
1608
|
+
Object.freeze(options.retry.statusCodes);
|
|
1540
1609
|
Object.freeze(options.context);
|
|
1541
1610
|
}
|
|
1542
1611
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type {
|
|
2
|
+
import type { Buffer } from 'node:buffer';
|
|
3
|
+
import type { URL } from 'node:url';
|
|
3
4
|
import type { IncomingMessageWithTimings, Timings } from '@szmarczak/http-timer';
|
|
4
5
|
import { RequestError } from './errors.js';
|
|
5
6
|
import type { ParseJsonFunction, ResponseType } from './options.js';
|
|
@@ -28,12 +28,12 @@ export const parseBody = (response, responseType, parseJson, encoding) => {
|
|
|
28
28
|
if (responseType === 'buffer') {
|
|
29
29
|
return rawBody;
|
|
30
30
|
}
|
|
31
|
-
throw new ParseError({
|
|
32
|
-
message: `Unknown body type '${responseType}'`,
|
|
33
|
-
name: 'Error',
|
|
34
|
-
}, response);
|
|
35
31
|
}
|
|
36
32
|
catch (error) {
|
|
37
33
|
throw new ParseError(error, response);
|
|
38
34
|
}
|
|
35
|
+
throw new ParseError({
|
|
36
|
+
message: `Unknown body type '${responseType}'`,
|
|
37
|
+
name: 'Error',
|
|
38
|
+
}, response);
|
|
39
39
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { Writable, Readable } from 'stream';
|
|
3
|
-
import type { ClientRequest } from 'http';
|
|
2
|
+
import type { Writable, Readable } from 'node:stream';
|
|
3
|
+
import type { ClientRequest } from 'node:http';
|
|
4
4
|
declare function isClientRequest(clientRequest: Writable | Readable): clientRequest is ClientRequest;
|
|
5
5
|
export default isClientRequest;
|
package/dist/source/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { got };
|
|
|
4
4
|
export { default as Options } from './core/options.js';
|
|
5
5
|
export * from './core/options.js';
|
|
6
6
|
export * from './core/response.js';
|
|
7
|
+
export type { default as Request } from './core/index.js';
|
|
7
8
|
export * from './core/index.js';
|
|
8
9
|
export * from './core/errors.js';
|
|
9
10
|
export { Delays } from './core/timed-out.js';
|
package/dist/source/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type {
|
|
2
|
+
import type { Buffer } from 'node:buffer';
|
|
3
|
+
import type { URL } from 'node:url';
|
|
3
4
|
import type { CancelableRequest } from './as-promise/types.js';
|
|
4
5
|
import type { Response } from './core/response.js';
|
|
5
6
|
import type Options from './core/options.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "got",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.1",
|
|
4
4
|
"description": "Human-friendly and powerful HTTP request library for Node.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/got",
|
|
@@ -44,60 +44,64 @@
|
|
|
44
44
|
"ky"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@sindresorhus/is": "^4.0
|
|
48
|
-
"@szmarczak/http-timer": "^
|
|
47
|
+
"@sindresorhus/is": "^4.2.0",
|
|
48
|
+
"@szmarczak/http-timer": "^5.0.1",
|
|
49
49
|
"@types/cacheable-request": "^6.0.2",
|
|
50
50
|
"@types/responselike": "^1.0.0",
|
|
51
|
-
"cacheable-lookup": "^6.0.
|
|
51
|
+
"cacheable-lookup": "^6.0.4",
|
|
52
52
|
"cacheable-request": "^7.0.2",
|
|
53
53
|
"decompress-response": "^6.0.0",
|
|
54
|
+
"form-data-encoder": "1.7.1",
|
|
54
55
|
"get-stream": "^6.0.1",
|
|
55
|
-
"http2-wrapper": "^2.
|
|
56
|
-
"lowercase-keys": "^
|
|
57
|
-
"p-cancelable": "^
|
|
56
|
+
"http2-wrapper": "^2.1.9",
|
|
57
|
+
"lowercase-keys": "^3.0.0",
|
|
58
|
+
"p-cancelable": "^3.0.0",
|
|
58
59
|
"responselike": "^2.0.0"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@hapi/bourne": "^2.0.0",
|
|
62
|
-
"@sindresorhus/tsconfig": "^
|
|
63
|
-
"@sinonjs/fake-timers": "^
|
|
63
|
+
"@sindresorhus/tsconfig": "^2.0.0",
|
|
64
|
+
"@sinonjs/fake-timers": "^8.1.0",
|
|
64
65
|
"@types/benchmark": "^2.1.1",
|
|
65
66
|
"@types/express": "^4.17.13",
|
|
66
|
-
"@types/node": "^
|
|
67
|
-
"@types/node-fetch": "^2.5.11",
|
|
67
|
+
"@types/node": "^16.11.12",
|
|
68
68
|
"@types/pem": "^1.9.6",
|
|
69
69
|
"@types/pify": "^5.0.1",
|
|
70
|
-
"@types/readable-stream": "^2.3.
|
|
71
|
-
"@types/request": "^2.48.
|
|
72
|
-
"@types/sinon": "^
|
|
70
|
+
"@types/readable-stream": "^2.3.12",
|
|
71
|
+
"@types/request": "^2.48.7",
|
|
72
|
+
"@types/sinon": "^10.0.6",
|
|
73
|
+
"@types/sinonjs__fake-timers": "^8.1.1",
|
|
73
74
|
"@types/tough-cookie": "^4.0.1",
|
|
74
75
|
"ava": "^3.15.0",
|
|
75
|
-
"axios": "^0.
|
|
76
|
+
"axios": "^0.24.0",
|
|
76
77
|
"benchmark": "^2.1.4",
|
|
78
|
+
"bluebird": "^3.7.2",
|
|
77
79
|
"body-parser": "^1.19.0",
|
|
78
80
|
"create-cert": "^1.0.6",
|
|
79
81
|
"create-test-server": "^3.0.1",
|
|
80
|
-
"del-cli": "^
|
|
82
|
+
"del-cli": "^4.0.1",
|
|
81
83
|
"delay": "^5.0.0",
|
|
82
84
|
"express": "^4.17.1",
|
|
83
85
|
"form-data": "^4.0.0",
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
86
|
+
"formdata-node": "^4.3.1",
|
|
87
|
+
"nock": "^13.2.1",
|
|
88
|
+
"node-fetch": "^3.1.0",
|
|
89
|
+
"np": "^7.6.0",
|
|
87
90
|
"nyc": "^15.1.0",
|
|
88
|
-
"p-event": "^
|
|
91
|
+
"p-event": "^5.0.1",
|
|
89
92
|
"pem": "^1.14.4",
|
|
90
93
|
"pify": "^5.0.0",
|
|
91
94
|
"readable-stream": "^3.6.0",
|
|
92
95
|
"request": "^2.88.2",
|
|
93
|
-
"sinon": "^
|
|
96
|
+
"sinon": "^12.0.1",
|
|
94
97
|
"slow-stream": "0.0.4",
|
|
95
|
-
"tempy": "^
|
|
98
|
+
"tempy": "^2.0.0",
|
|
99
|
+
"then-busboy": "^5.1.1",
|
|
96
100
|
"to-readable-stream": "^3.0.0",
|
|
97
101
|
"tough-cookie": "^4.0.0",
|
|
98
|
-
"ts-node": "^10.
|
|
99
|
-
"typescript": "4.3
|
|
100
|
-
"xo": "^0.
|
|
102
|
+
"ts-node": "^10.4.0",
|
|
103
|
+
"typescript": "4.5.3",
|
|
104
|
+
"xo": "^0.47.0"
|
|
101
105
|
},
|
|
102
106
|
"types": "dist/source",
|
|
103
107
|
"sideEffects": false,
|
|
@@ -146,7 +150,9 @@
|
|
|
146
150
|
"@typescript-eslint/no-unsafe-return": "off",
|
|
147
151
|
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
148
152
|
"@typescript-eslint/no-unsafe-call": "off",
|
|
149
|
-
"@typescript-eslint/await-thenable": "off"
|
|
153
|
+
"@typescript-eslint/await-thenable": "off",
|
|
154
|
+
"no-lone-blocks": "off",
|
|
155
|
+
"unicorn/no-await-expression-member": "off"
|
|
150
156
|
}
|
|
151
157
|
},
|
|
152
158
|
"runkitExampleFilename": "./documentation/examples/runkit-example.js"
|