got 12.0.0-beta.4 → 12.0.2
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 +4 -8
- 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 +31 -8
- package/dist/source/core/options.d.ts +183 -66
- package/dist/source/core/options.js +38 -31
- package/dist/source/core/response.d.ts +2 -1
- package/dist/source/core/response.js +5 -5
- 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 +35 -29
- package/readme.md +86 -75
|
@@ -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) {
|
|
@@ -148,13 +151,13 @@ const defaultInternals = {
|
|
|
148
151
|
responseType: 'text',
|
|
149
152
|
url: undefined,
|
|
150
153
|
pagination: {
|
|
151
|
-
transform
|
|
154
|
+
transform(response) {
|
|
152
155
|
if (response.request.options.responseType === 'json') {
|
|
153
156
|
return response.body;
|
|
154
157
|
}
|
|
155
158
|
return JSON.parse(response.body);
|
|
156
159
|
},
|
|
157
|
-
paginate
|
|
160
|
+
paginate({ response }) {
|
|
158
161
|
const rawLinkHeader = response.headers.link;
|
|
159
162
|
if (typeof rawLinkHeader !== 'string' || rawLinkHeader.trim() === '') {
|
|
160
163
|
return false;
|
|
@@ -213,62 +216,64 @@ const cloneInternals = (internals) => {
|
|
|
213
216
|
const cloneRaw = (raw) => {
|
|
214
217
|
const { hooks, retry } = raw;
|
|
215
218
|
const result = { ...raw };
|
|
216
|
-
if (raw.context) {
|
|
219
|
+
if (is.object(raw.context)) {
|
|
217
220
|
result.context = { ...raw.context };
|
|
218
221
|
}
|
|
219
|
-
if (raw.cacheOptions) {
|
|
222
|
+
if (is.object(raw.cacheOptions)) {
|
|
220
223
|
result.cacheOptions = { ...raw.cacheOptions };
|
|
221
224
|
}
|
|
222
|
-
if (raw.https) {
|
|
225
|
+
if (is.object(raw.https)) {
|
|
223
226
|
result.https = { ...raw.https };
|
|
224
227
|
}
|
|
225
|
-
if (raw.cacheOptions) {
|
|
228
|
+
if (is.object(raw.cacheOptions)) {
|
|
226
229
|
result.cacheOptions = { ...result.cacheOptions };
|
|
227
230
|
}
|
|
228
|
-
if (raw.agent) {
|
|
231
|
+
if (is.object(raw.agent)) {
|
|
229
232
|
result.agent = { ...raw.agent };
|
|
230
233
|
}
|
|
231
|
-
if (raw.headers) {
|
|
234
|
+
if (is.object(raw.headers)) {
|
|
232
235
|
result.headers = { ...raw.headers };
|
|
233
236
|
}
|
|
234
|
-
if (retry) {
|
|
237
|
+
if (is.object(retry)) {
|
|
235
238
|
result.retry = { ...retry };
|
|
236
|
-
if (retry.errorCodes) {
|
|
239
|
+
if (is.array(retry.errorCodes)) {
|
|
237
240
|
result.retry.errorCodes = [...retry.errorCodes];
|
|
238
241
|
}
|
|
239
|
-
if (retry.methods) {
|
|
242
|
+
if (is.array(retry.methods)) {
|
|
240
243
|
result.retry.methods = [...retry.methods];
|
|
241
244
|
}
|
|
242
|
-
if (retry.statusCodes) {
|
|
245
|
+
if (is.array(retry.statusCodes)) {
|
|
243
246
|
result.retry.statusCodes = [...retry.statusCodes];
|
|
244
247
|
}
|
|
245
248
|
}
|
|
246
|
-
if (raw.timeout) {
|
|
249
|
+
if (is.object(raw.timeout)) {
|
|
247
250
|
result.timeout = { ...raw.timeout };
|
|
248
251
|
}
|
|
249
|
-
if (hooks) {
|
|
250
|
-
result.hooks = {
|
|
251
|
-
|
|
252
|
+
if (is.object(hooks)) {
|
|
253
|
+
result.hooks = {
|
|
254
|
+
...hooks,
|
|
255
|
+
};
|
|
256
|
+
if (is.array(hooks.init)) {
|
|
252
257
|
result.hooks.init = [...hooks.init];
|
|
253
258
|
}
|
|
254
|
-
if (hooks.beforeRequest) {
|
|
259
|
+
if (is.array(hooks.beforeRequest)) {
|
|
255
260
|
result.hooks.beforeRequest = [...hooks.beforeRequest];
|
|
256
261
|
}
|
|
257
|
-
if (hooks.beforeError) {
|
|
262
|
+
if (is.array(hooks.beforeError)) {
|
|
258
263
|
result.hooks.beforeError = [...hooks.beforeError];
|
|
259
264
|
}
|
|
260
|
-
if (hooks.beforeRedirect) {
|
|
265
|
+
if (is.array(hooks.beforeRedirect)) {
|
|
261
266
|
result.hooks.beforeRedirect = [...hooks.beforeRedirect];
|
|
262
267
|
}
|
|
263
|
-
if (hooks.beforeRetry) {
|
|
268
|
+
if (is.array(hooks.beforeRetry)) {
|
|
264
269
|
result.hooks.beforeRetry = [...hooks.beforeRetry];
|
|
265
270
|
}
|
|
266
|
-
if (hooks.afterResponse) {
|
|
271
|
+
if (is.array(hooks.afterResponse)) {
|
|
267
272
|
result.hooks.afterResponse = [...hooks.afterResponse];
|
|
268
273
|
}
|
|
269
274
|
}
|
|
270
275
|
// TODO: raw.searchParams
|
|
271
|
-
if (raw.pagination) {
|
|
276
|
+
if (is.object(raw.pagination)) {
|
|
272
277
|
result.pagination = { ...raw.pagination };
|
|
273
278
|
}
|
|
274
279
|
return result;
|
|
@@ -594,7 +599,7 @@ export default class Options {
|
|
|
594
599
|
|
|
595
600
|
__Note #4__: This option is not enumerable and will not be merged with the instance defaults.
|
|
596
601
|
|
|
597
|
-
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`.
|
|
598
603
|
|
|
599
604
|
Since Got 12, the `content-length` is not automatically set when `body` is a `fs.createReadStream`.
|
|
600
605
|
*/
|
|
@@ -602,7 +607,7 @@ export default class Options {
|
|
|
602
607
|
return this._internals.body;
|
|
603
608
|
}
|
|
604
609
|
set body(value) {
|
|
605
|
-
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);
|
|
606
611
|
if (is.nodeStream(value)) {
|
|
607
612
|
assert.truthy(value.readable);
|
|
608
613
|
}
|
|
@@ -1494,6 +1499,7 @@ export default class Options {
|
|
|
1494
1499
|
assert.any([is.number, is.undefined], value);
|
|
1495
1500
|
this._internals.maxHeaderSize = value;
|
|
1496
1501
|
}
|
|
1502
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1497
1503
|
toJSON() {
|
|
1498
1504
|
return { ...this._internals };
|
|
1499
1505
|
}
|
|
@@ -1522,6 +1528,7 @@ export default class Options {
|
|
|
1522
1528
|
...internals.cacheOptions,
|
|
1523
1529
|
...this._unixOptions,
|
|
1524
1530
|
// HTTPS options
|
|
1531
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1525
1532
|
ALPNProtocols: https.alpnProtocols,
|
|
1526
1533
|
ca: https.certificateAuthority,
|
|
1527
1534
|
cert: https.certificate,
|
|
@@ -1576,9 +1583,9 @@ export default class Options {
|
|
|
1576
1583
|
}
|
|
1577
1584
|
return http2wrapper.auto;
|
|
1578
1585
|
}
|
|
1579
|
-
return
|
|
1586
|
+
return https.request;
|
|
1580
1587
|
}
|
|
1581
|
-
return
|
|
1588
|
+
return http.request;
|
|
1582
1589
|
}
|
|
1583
1590
|
freeze() {
|
|
1584
1591
|
const options = this._internals;
|
|
@@ -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';
|
|
@@ -23,17 +23,17 @@ export const parseBody = (response, responseType, parseJson, encoding) => {
|
|
|
23
23
|
return rawBody.toString(encoding);
|
|
24
24
|
}
|
|
25
25
|
if (responseType === 'json') {
|
|
26
|
-
return rawBody.length === 0 ? '' : parseJson(rawBody.toString());
|
|
26
|
+
return rawBody.length === 0 ? '' : parseJson(rawBody.toString(encoding));
|
|
27
27
|
}
|
|
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.2",
|
|
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.6.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.10",
|
|
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": "^9.1.1",
|
|
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": "^17.0.21",
|
|
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.13",
|
|
71
|
+
"@types/request": "^2.48.8",
|
|
72
|
+
"@types/sinon": "^10.0.11",
|
|
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.26.1",
|
|
76
77
|
"benchmark": "^2.1.4",
|
|
77
|
-
"
|
|
78
|
+
"bluebird": "^3.7.2",
|
|
79
|
+
"body-parser": "^1.19.2",
|
|
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
|
-
"express": "^4.17.
|
|
84
|
+
"express": "^4.17.3",
|
|
83
85
|
"form-data": "^4.0.0",
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
86
|
+
"formdata-node": "^4.3.2",
|
|
87
|
+
"nock": "^13.2.4",
|
|
88
|
+
"node-fetch": "^3.2.3",
|
|
89
|
+
"np": "^7.6.0",
|
|
87
90
|
"nyc": "^15.1.0",
|
|
88
|
-
"p-event": "^
|
|
89
|
-
"pem": "^1.14.
|
|
91
|
+
"p-event": "^5.0.1",
|
|
92
|
+
"pem": "^1.14.6",
|
|
90
93
|
"pify": "^5.0.0",
|
|
91
94
|
"readable-stream": "^3.6.0",
|
|
92
95
|
"request": "^2.88.2",
|
|
93
|
-
"sinon": "^
|
|
96
|
+
"sinon": "^13.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.
|
|
100
|
-
"xo": "^0.
|
|
102
|
+
"ts-node": "^10.7.0",
|
|
103
|
+
"typescript": "4.6.2",
|
|
104
|
+
"xo": "^0.48.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"
|