got 15.0.0 → 15.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.js +82 -80
- package/dist/source/core/errors.js +3 -3
- package/dist/source/core/index.js +24 -21
- package/dist/source/core/options.d.ts +25 -25
- package/dist/source/core/options.js +8 -10
- package/dist/source/core/timed-out.js +1 -1
- package/dist/source/core/utils/is-unix-socket-url.d.ts +1 -1
- package/dist/source/core/utils/is-unix-socket-url.js +3 -4
- package/dist/source/types.d.ts +6 -7
- package/package.json +1 -1
- package/readme.md +0 -3
|
@@ -24,97 +24,99 @@ export default function asPromise(firstRequest) {
|
|
|
24
24
|
request.retryCount = retryCount;
|
|
25
25
|
request._noPipe = true;
|
|
26
26
|
globalRequest = request;
|
|
27
|
-
request.once('response',
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
else {
|
|
36
|
-
try {
|
|
37
|
-
response.body = parseBody(response, options.responseType, options.parseJson, options.encoding);
|
|
27
|
+
request.once('response', (response) => {
|
|
28
|
+
void (async () => {
|
|
29
|
+
// Parse body
|
|
30
|
+
const contentEncoding = (response.headers['content-encoding'] ?? '').toLowerCase();
|
|
31
|
+
const isCompressed = compressedEncodings.has(contentEncoding);
|
|
32
|
+
const { options } = request;
|
|
33
|
+
if (isCompressed && !options.decompress) {
|
|
34
|
+
response.body = response.rawBody;
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
// Fall back to `utf8`
|
|
36
|
+
else {
|
|
41
37
|
try {
|
|
42
|
-
response.body =
|
|
38
|
+
response.body = parseBody(response, options.responseType, options.parseJson, options.encoding);
|
|
43
39
|
}
|
|
44
40
|
catch (error) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (isResponseOk(response)) {
|
|
49
|
-
request._beforeError(normalizeError(error));
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
const hooks = options.hooks.afterResponse;
|
|
56
|
-
for (const [index, hook] of hooks.entries()) {
|
|
57
|
-
const previousUrl = options.url ? new URL(options.url) : undefined;
|
|
58
|
-
const previousState = previousUrl ? snapshotCrossOriginState(options) : undefined;
|
|
59
|
-
const requestOptions = response.request.options;
|
|
60
|
-
const responseSnapshot = response;
|
|
61
|
-
// @ts-expect-error TS doesn't notice that RequestPromise is a Promise
|
|
62
|
-
// eslint-disable-next-line no-await-in-loop
|
|
63
|
-
response = await requestOptions.trackStateMutations(async (changedState) => hook(responseSnapshot, async (updatedOptions) => {
|
|
64
|
-
const preserveHooks = updatedOptions.preserveHooks ?? false;
|
|
65
|
-
const reusesRequestOptions = updatedOptions === requestOptions;
|
|
66
|
-
const hasExplicitBody = reusesRequestOptions
|
|
67
|
-
? changedState.has('body') || changedState.has('json') || changedState.has('form')
|
|
68
|
-
: (Object.hasOwn(updatedOptions, 'body') && updatedOptions.body !== undefined)
|
|
69
|
-
|| (Object.hasOwn(updatedOptions, 'json') && updatedOptions.json !== undefined)
|
|
70
|
-
|| (Object.hasOwn(updatedOptions, 'form') && updatedOptions.form !== undefined);
|
|
71
|
-
if (hasExplicitBody && !reusesRequestOptions) {
|
|
72
|
-
options.clearBody();
|
|
41
|
+
// Fall back to `utf8`
|
|
42
|
+
try {
|
|
43
|
+
response.body = decodeUint8Array(response.rawBody);
|
|
73
44
|
}
|
|
74
|
-
|
|
75
|
-
|
|
45
|
+
catch (error) {
|
|
46
|
+
request._beforeError(new ParseError(normalizeError(error), response));
|
|
47
|
+
return;
|
|
76
48
|
}
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
49
|
+
if (isResponseOk(response)) {
|
|
50
|
+
request._beforeError(normalizeError(error));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const hooks = options.hooks.afterResponse;
|
|
57
|
+
for (const [index, hook] of hooks.entries()) {
|
|
58
|
+
const previousUrl = options.url ? new URL(options.url) : undefined;
|
|
59
|
+
const previousState = previousUrl ? snapshotCrossOriginState(options) : undefined;
|
|
60
|
+
const requestOptions = response.request.options;
|
|
61
|
+
const responseSnapshot = response;
|
|
62
|
+
// @ts-expect-error TS doesn't notice that RequestPromise is a Promise
|
|
63
|
+
// eslint-disable-next-line no-await-in-loop
|
|
64
|
+
response = await requestOptions.trackStateMutations(async (changedState) => hook(responseSnapshot, async (updatedOptions) => {
|
|
65
|
+
const preserveHooks = updatedOptions.preserveHooks ?? false;
|
|
66
|
+
const reusesRequestOptions = updatedOptions === requestOptions;
|
|
67
|
+
const hasExplicitBody = reusesRequestOptions
|
|
68
|
+
? changedState.has('body') || changedState.has('json') || changedState.has('form')
|
|
69
|
+
: (Object.hasOwn(updatedOptions, 'body') && updatedOptions.body !== undefined)
|
|
70
|
+
|| (Object.hasOwn(updatedOptions, 'json') && updatedOptions.json !== undefined)
|
|
71
|
+
|| (Object.hasOwn(updatedOptions, 'form') && updatedOptions.form !== undefined);
|
|
72
|
+
if (hasExplicitBody && !reusesRequestOptions) {
|
|
73
|
+
options.clearBody();
|
|
74
|
+
}
|
|
75
|
+
if (!reusesRequestOptions) {
|
|
76
|
+
options.merge(updatedOptions);
|
|
77
|
+
}
|
|
78
|
+
if (updatedOptions.url) {
|
|
79
|
+
const nextUrl = reusesRequestOptions
|
|
80
|
+
? options.url
|
|
81
|
+
: applyUrlOverride(options, updatedOptions.url, updatedOptions);
|
|
82
|
+
if (previousUrl) {
|
|
83
|
+
if (reusesRequestOptions && !isSameOrigin(previousUrl, nextUrl)) {
|
|
84
|
+
options.stripUnchangedCrossOriginState(previousState, changedState, { clearBody: !hasExplicitBody });
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
options.stripSensitiveHeaders(previousUrl, nextUrl, updatedOptions);
|
|
88
|
+
if (!isSameOrigin(previousUrl, nextUrl) && !hasExplicitBody) {
|
|
89
|
+
options.clearBody();
|
|
90
|
+
}
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
}
|
|
94
|
+
// Remove any further hooks for that request, because we'll call them anyway.
|
|
95
|
+
// The loop continues. We don't want duplicates (asPromise recursion).
|
|
96
|
+
// Unless preserveHooks is true, in which case we keep the remaining hooks.
|
|
97
|
+
if (!preserveHooks) {
|
|
98
|
+
options.hooks.afterResponse = options.hooks.afterResponse.slice(0, index);
|
|
99
|
+
}
|
|
100
|
+
throw new RetryError(request);
|
|
101
|
+
}));
|
|
102
|
+
if (!(is.object(response) && is.number(response.statusCode) && 'body' in response)) {
|
|
103
|
+
throw new TypeError('The `afterResponse` hook returned an invalid value');
|
|
92
104
|
}
|
|
93
|
-
// Remove any further hooks for that request, because we'll call them anyway.
|
|
94
|
-
// The loop continues. We don't want duplicates (asPromise recursion).
|
|
95
|
-
// Unless preserveHooks is true, in which case we keep the remaining hooks.
|
|
96
|
-
if (!preserveHooks) {
|
|
97
|
-
options.hooks.afterResponse = options.hooks.afterResponse.slice(0, index);
|
|
98
|
-
}
|
|
99
|
-
throw new RetryError(request);
|
|
100
|
-
}));
|
|
101
|
-
if (!(is.object(response) && is.number(response.statusCode) && 'body' in response)) {
|
|
102
|
-
throw new TypeError('The `afterResponse` hook returned an invalid value');
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
107
|
+
catch (error) {
|
|
108
|
+
request._beforeError(normalizeError(error));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
globalResponse = response;
|
|
112
|
+
if (!isResponseOk(response)) {
|
|
113
|
+
request._beforeError(new HTTPError(response));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
request.destroy();
|
|
117
|
+
promiseSettled = true;
|
|
118
|
+
resolve(request.options.resolveBodyOnly ? response.body : response);
|
|
119
|
+
})();
|
|
118
120
|
});
|
|
119
121
|
let handledFinalError = false;
|
|
120
122
|
const onError = (error) => {
|
|
@@ -191,7 +193,7 @@ export default function asPromise(firstRequest) {
|
|
|
191
193
|
const { options } = globalResponse.request;
|
|
192
194
|
if (responseType === 'text') {
|
|
193
195
|
const text = decodeUint8Array(globalResponse.rawBody, options.encoding);
|
|
194
|
-
return (isUtf8Encoding(options.encoding) ? text.replace(/^\
|
|
196
|
+
return (isUtf8Encoding(options.encoding) ? text.replace(/^\u{FEFF}/v, '') : text);
|
|
195
197
|
}
|
|
196
198
|
return parseBody(globalResponse, responseType, options.parseJson, options.encoding);
|
|
197
199
|
})();
|
|
@@ -41,13 +41,13 @@ export class RequestError extends Error {
|
|
|
41
41
|
// Recover the original stacktrace
|
|
42
42
|
if (is.string(error.stack) && is.string(this.stack)) {
|
|
43
43
|
const indexOfMessage = this.stack.indexOf(this.message) + this.message.length;
|
|
44
|
-
const thisStackTrace = this.stack.slice(indexOfMessage).split('\n').
|
|
45
|
-
const errorStackTrace = error.stack.slice(error.stack.indexOf(error.message) + error.message.length).split('\n').
|
|
44
|
+
const thisStackTrace = this.stack.slice(indexOfMessage).split('\n').toReversed();
|
|
45
|
+
const errorStackTrace = error.stack.slice(error.stack.indexOf(error.message) + error.message.length).split('\n').toReversed();
|
|
46
46
|
// Remove duplicated traces
|
|
47
47
|
while (errorStackTrace.length > 0 && errorStackTrace[0] === thisStackTrace[0]) {
|
|
48
48
|
thisStackTrace.shift();
|
|
49
49
|
}
|
|
50
|
-
this.stack = `${this.stack.slice(0, indexOfMessage)}${thisStackTrace.
|
|
50
|
+
this.stack = `${this.stack.slice(0, indexOfMessage)}${thisStackTrace.toReversed().join('\n')}${errorStackTrace.toReversed().join('\n')}`;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -1319,7 +1319,8 @@ export default class Request extends Duplex {
|
|
|
1319
1319
|
try {
|
|
1320
1320
|
const result = iterableBody.return();
|
|
1321
1321
|
if (result instanceof Promise) {
|
|
1322
|
-
|
|
1322
|
+
// eslint-disable-next-line promise/prefer-await-to-then
|
|
1323
|
+
result.catch(noop);
|
|
1323
1324
|
}
|
|
1324
1325
|
}
|
|
1325
1326
|
catch { }
|
|
@@ -1493,28 +1494,30 @@ export default class Request extends Duplex {
|
|
|
1493
1494
|
});
|
|
1494
1495
|
let request;
|
|
1495
1496
|
// TODO: Fix `cacheable-response`. This is ugly.
|
|
1496
|
-
const cacheRequest = cacheableStore.get(options.cache)(options,
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1497
|
+
const cacheRequest = cacheableStore.get(options.cache)(options, (response) => {
|
|
1498
|
+
void (async () => {
|
|
1499
|
+
response._readableState.autoDestroy = false;
|
|
1500
|
+
if (request) {
|
|
1501
|
+
const fix = () => {
|
|
1502
|
+
// For ResponseLike objects from cache, set complete to true if not already set.
|
|
1503
|
+
// For real HTTP responses, copy from the underlying response.
|
|
1504
|
+
if (response.req) {
|
|
1505
|
+
response.complete = response.req.res.complete;
|
|
1506
|
+
}
|
|
1507
|
+
else if (response.complete === undefined) {
|
|
1508
|
+
// ResponseLike from cache should have complete = true
|
|
1509
|
+
response.complete = true;
|
|
1510
|
+
}
|
|
1511
|
+
};
|
|
1512
|
+
response.prependOnceListener('end', fix);
|
|
1513
|
+
fix();
|
|
1514
|
+
(await request).emit('cacheableResponse', response);
|
|
1515
|
+
}
|
|
1516
|
+
resolve(response);
|
|
1517
|
+
})();
|
|
1515
1518
|
});
|
|
1516
1519
|
cacheRequest.once('error', reject);
|
|
1517
|
-
cacheRequest.once('request',
|
|
1520
|
+
cacheRequest.once('request', (requestOrPromise) => {
|
|
1518
1521
|
request = requestOrPromise;
|
|
1519
1522
|
resolve(request);
|
|
1520
1523
|
});
|
|
@@ -91,20 +91,20 @@ export type Hooks = {
|
|
|
91
91
|
|
|
92
92
|
@default []
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
Note:
|
|
95
95
|
> - This hook must be synchronous.
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
Note:
|
|
98
98
|
> - This is called every time options are merged.
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
Note:
|
|
101
101
|
> - The `options` object may not have the `url` property. To modify it, use a `beforeRequest` hook instead.
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
Note:
|
|
104
104
|
> - This hook is called when a new instance of `Options` is created.
|
|
105
105
|
> - Do not confuse this with the creation of `Request` or `got(…)`.
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
Note:
|
|
108
108
|
> - When using `got(url)` or `got(url, undefined, defaults)` this hook will **not** be called.
|
|
109
109
|
|
|
110
110
|
This is especially useful in conjunction with `got.extend()` when the input needs custom handling.
|
|
@@ -183,10 +183,10 @@ export type Hooks = {
|
|
|
183
183
|
|
|
184
184
|
@default []
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
Note:
|
|
187
187
|
> - Got will make no further changes to the request before it is sent.
|
|
188
188
|
|
|
189
|
-
|
|
189
|
+
Note:
|
|
190
190
|
> - Changing `options.json` or `options.form` has no effect on the request. You should change `options.body` instead. If needed, update the `options.headers` accordingly.
|
|
191
191
|
|
|
192
192
|
@example
|
|
@@ -209,7 +209,7 @@ export type Hooks = {
|
|
|
209
209
|
);
|
|
210
210
|
```
|
|
211
211
|
|
|
212
|
-
|
|
212
|
+
Example using `context.retryCount`:
|
|
213
213
|
|
|
214
214
|
```
|
|
215
215
|
import got from 'got';
|
|
@@ -231,7 +231,7 @@ export type Hooks = {
|
|
|
231
231
|
});
|
|
232
232
|
```
|
|
233
233
|
|
|
234
|
-
|
|
234
|
+
Tip:
|
|
235
235
|
> - You can indirectly override the `request` function by early returning a [`ClientRequest`-like](https://nodejs.org/api/http.html#http_class_http_clientrequest) instance or a [`IncomingMessage`-like](https://nodejs.org/api/http.html#http_class_http_incomingmessage) instance. This is very useful when creating a custom cache mechanism.
|
|
236
236
|
> - [Read more about this tip](https://github.com/sindresorhus/got/blob/main/documentation/cache.md#advanced-caching-mechanisms).
|
|
237
237
|
*/
|
|
@@ -241,7 +241,7 @@ export type Hooks = {
|
|
|
241
241
|
|
|
242
242
|
@default []
|
|
243
243
|
|
|
244
|
-
|
|
244
|
+
Tip:
|
|
245
245
|
> - This is especially useful when you want to avoid dead sites.
|
|
246
246
|
|
|
247
247
|
@example
|
|
@@ -326,13 +326,13 @@ export type Hooks = {
|
|
|
326
326
|
|
|
327
327
|
@default []
|
|
328
328
|
|
|
329
|
-
|
|
329
|
+
Note:
|
|
330
330
|
> - When using the Stream API, this hook is ignored.
|
|
331
331
|
|
|
332
|
-
|
|
332
|
+
Note:
|
|
333
333
|
> - When retrying, the `beforeRequest` hook is called afterwards.
|
|
334
334
|
|
|
335
|
-
|
|
335
|
+
Note:
|
|
336
336
|
> - If no retry occurs, the `beforeError` hook is called instead.
|
|
337
337
|
|
|
338
338
|
This hook is especially useful when you want to retrieve the cause of a retry.
|
|
@@ -361,31 +361,31 @@ export type Hooks = {
|
|
|
361
361
|
|
|
362
362
|
@default []
|
|
363
363
|
|
|
364
|
-
|
|
364
|
+
Return value:
|
|
365
365
|
> - `false` - Prevent caching (remaining hooks are skipped)
|
|
366
366
|
> - `void`/`undefined` - Use default caching behavior (mutations take effect)
|
|
367
367
|
|
|
368
|
-
|
|
368
|
+
Modifying the response:
|
|
369
369
|
> - Hooks can directly mutate response properties like `headers`, `statusCode`, and `statusMessage`
|
|
370
370
|
> - Mutations to `response.headers` affect how the caching layer decides whether to cache the response and for how long
|
|
371
371
|
> - Changes are applied to what gets cached
|
|
372
372
|
|
|
373
|
-
|
|
373
|
+
Note:
|
|
374
374
|
> - This hook is only called when the `cache` option is enabled.
|
|
375
375
|
|
|
376
|
-
|
|
376
|
+
Note:
|
|
377
377
|
> - This hook must be synchronous. It cannot return a Promise. If you need async logic to determine caching behavior, use a `beforeRequest` hook instead.
|
|
378
378
|
|
|
379
|
-
|
|
379
|
+
Note:
|
|
380
380
|
> - When returning `false`, remaining hooks are skipped and the response will not be cached.
|
|
381
381
|
|
|
382
|
-
|
|
382
|
+
Note:
|
|
383
383
|
> - Returning anything other than `false` or `undefined` will throw a TypeError.
|
|
384
384
|
|
|
385
|
-
|
|
385
|
+
Note:
|
|
386
386
|
> - If a hook throws an error, it will be propagated and the request will fail. This is consistent with how other hooks in Got handle errors.
|
|
387
387
|
|
|
388
|
-
|
|
388
|
+
Note:
|
|
389
389
|
> - At this stage, the response body has not been read yet - it's still a stream. Properties like `response.body` and `response.rawBody` are not available. You can only inspect/modify response headers and status code.
|
|
390
390
|
|
|
391
391
|
@example
|
|
@@ -425,17 +425,17 @@ export type Hooks = {
|
|
|
425
425
|
|
|
426
426
|
@default []
|
|
427
427
|
|
|
428
|
-
|
|
428
|
+
Note:
|
|
429
429
|
> - When using the Stream API, this hook is ignored.
|
|
430
430
|
|
|
431
|
-
|
|
431
|
+
Note:
|
|
432
432
|
> - Calling the `retryWithMergedOptions` function will trigger `beforeRetry` hooks. By default, remaining `afterResponse` hooks are removed to prevent duplicate execution. To preserve remaining hooks on retry, set `preserveHooks: true` in the options passed to `retryWithMergedOptions`. In case of an error, `beforeRetry` hooks will be called instead.
|
|
433
433
|
Meanwhile the `init`, `beforeRequest` , `beforeRedirect` as well as already executed `afterResponse` hooks will be skipped.
|
|
434
434
|
|
|
435
|
-
|
|
435
|
+
Note:
|
|
436
436
|
> - To preserve remaining `afterResponse` hooks after calling `retryWithMergedOptions`, set `preserveHooks: true` in the options passed to `retryWithMergedOptions`. This is useful when you want hooks to run on retried requests.
|
|
437
437
|
|
|
438
|
-
|
|
438
|
+
Warning:
|
|
439
439
|
> - Be cautious when using `preserveHooks: true`. If a hook unconditionally calls `retryWithMergedOptions` with `preserveHooks: true`, it will create an infinite retry loop. Always ensure hooks have proper conditional logic to avoid infinite retries.
|
|
440
440
|
|
|
441
441
|
@example
|
|
@@ -68,8 +68,8 @@ function hasCredentialInUrl(url, credential) {
|
|
|
68
68
|
}
|
|
69
69
|
export const hasExplicitCredentialInUrlChange = (changedState, url, credential) => (changedState.has(credential)
|
|
70
70
|
|| (changedState.has('url') && url?.[credential] !== ''));
|
|
71
|
-
const hasProtocolSlashes = (value) => /^[a-z][a-z
|
|
72
|
-
const hasHttpProtocolWithoutSlashes = (value) => /^https?:(?!\/\/)/
|
|
71
|
+
const hasProtocolSlashes = (value) => /^[a-z][\d+\-.a-z]*:\/\//iv.test(value);
|
|
72
|
+
const hasHttpProtocolWithoutSlashes = (value) => /^https?:(?!\/\/)/iv.test(value);
|
|
73
73
|
export function applyUrlOverride(options, url, { username, password } = {}) {
|
|
74
74
|
if (is.string(url) && options.url) {
|
|
75
75
|
url = new URL(url, options.url).toString();
|
|
@@ -486,7 +486,7 @@ export default class Options {
|
|
|
486
486
|
// would get merged. Instead we set the `searchParams` first, then
|
|
487
487
|
// `url.searchParams` is overwritten as expected.
|
|
488
488
|
//
|
|
489
|
-
/* eslint-disable no-unsafe-finally */
|
|
489
|
+
/* eslint-disable no-unsafe-finally -- `finally` is used intentionally here to ensure `url` is always set last, overwriting any merged searchParams */
|
|
490
490
|
try {
|
|
491
491
|
if (is.plainObject(input)) {
|
|
492
492
|
try {
|
|
@@ -912,16 +912,14 @@ export default class Options {
|
|
|
912
912
|
this.#internals.cookieJar = undefined;
|
|
913
913
|
return;
|
|
914
914
|
}
|
|
915
|
-
|
|
915
|
+
const { setCookie, getCookieString } = value;
|
|
916
916
|
assert.function(setCookie);
|
|
917
917
|
assert.function(getCookieString);
|
|
918
918
|
/* istanbul ignore next: Horrible `tough-cookie` v3 check */
|
|
919
919
|
if (setCookie.length === 4 && getCookieString.length === 0) {
|
|
920
|
-
setCookie = promisify(setCookie.bind(value));
|
|
921
|
-
getCookieString = promisify(getCookieString.bind(value));
|
|
922
920
|
this.#internals.cookieJar = {
|
|
923
|
-
setCookie,
|
|
924
|
-
getCookieString: getCookieString,
|
|
921
|
+
setCookie: promisify(setCookie.bind(value)),
|
|
922
|
+
getCookieString: promisify(getCookieString.bind(value)),
|
|
925
923
|
};
|
|
926
924
|
}
|
|
927
925
|
else {
|
|
@@ -1792,11 +1790,11 @@ export default class Options {
|
|
|
1792
1790
|
this.#internals.resolveBodyOnly = value;
|
|
1793
1791
|
}
|
|
1794
1792
|
/**
|
|
1795
|
-
@internal
|
|
1796
1793
|
Returns a `Stream` instead of a `Promise`.
|
|
1797
1794
|
Set internally by `got.stream()`.
|
|
1798
1795
|
|
|
1799
1796
|
@default false
|
|
1797
|
+
@internal
|
|
1800
1798
|
*/
|
|
1801
1799
|
get isStream() {
|
|
1802
1800
|
return this.#internals.isStream;
|
|
@@ -1945,7 +1943,7 @@ export default class Options {
|
|
|
1945
1943
|
}
|
|
1946
1944
|
let unixSocketGroups;
|
|
1947
1945
|
if (unixSocketPath !== undefined) {
|
|
1948
|
-
unixSocketGroups =
|
|
1946
|
+
unixSocketGroups = /^(?<socketPath>[^:]+):(?<path>.+)$/v.exec(`${url.pathname}${url.search}`)?.groups;
|
|
1949
1947
|
}
|
|
1950
1948
|
const unixOptions = unixSocketGroups
|
|
1951
1949
|
? { socketPath: unixSocketGroups.socketPath, path: unixSocketGroups.path, host: '' }
|
|
@@ -81,7 +81,7 @@ export default function timedOut(request, delays, options) {
|
|
|
81
81
|
const { socketPath } = request;
|
|
82
82
|
/* istanbul ignore next: hard to test */
|
|
83
83
|
if (socket.connecting) {
|
|
84
|
-
const hasPath = Boolean(socketPath ?? net.isIP(hostname ?? host ?? '') !== 0);
|
|
84
|
+
const hasPath = Boolean(socketPath ?? (net.isIP(hostname ?? host ?? '') !== 0));
|
|
85
85
|
if (hasLookup && !hasPath && socket.address().address === undefined) {
|
|
86
86
|
const cancelTimeout = addTimeout(delays.lookup, timeoutHandler, 'lookup');
|
|
87
87
|
once(socket, 'lookup', cancelTimeout);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export default function isUnixSocketURL(url) {
|
|
1
|
+
export default function isUnixSocketUrl(url) {
|
|
3
2
|
return url.protocol === 'unix:' || url.hostname === 'unix';
|
|
4
3
|
}
|
|
5
4
|
/**
|
|
@@ -18,8 +17,8 @@ getUnixSocketPath(new URL('http://example.com'));
|
|
|
18
17
|
```
|
|
19
18
|
*/
|
|
20
19
|
export function getUnixSocketPath(url) {
|
|
21
|
-
if (!
|
|
20
|
+
if (!isUnixSocketUrl(url)) {
|
|
22
21
|
return undefined;
|
|
23
22
|
}
|
|
24
|
-
return
|
|
23
|
+
return /^(?<socketPath>[^:]+):/v.exec(`${url.pathname}${url.search}`)?.groups?.socketPath;
|
|
25
24
|
}
|
package/dist/source/types.d.ts
CHANGED
|
@@ -59,10 +59,9 @@ export type ExtendOptions = {
|
|
|
59
59
|
*/
|
|
60
60
|
mutableDefaults?: boolean;
|
|
61
61
|
} & Except<OptionsInit, 'url'>;
|
|
62
|
-
type
|
|
63
|
-
export type StrictOptions = Except<
|
|
64
|
-
export type
|
|
65
|
-
export type OptionsWithPagination<T = unknown, R = unknown> = Merge<OptionsInitWithoutUrl, {
|
|
62
|
+
export type StreamOptions = Except<OptionsInit, 'url'>;
|
|
63
|
+
export type StrictOptions = Except<StreamOptions, 'responseType' | 'resolveBodyOnly'>;
|
|
64
|
+
export type OptionsWithPagination<T = unknown, R = unknown> = Merge<StreamOptions, {
|
|
66
65
|
pagination?: PaginationOptions<T, R>;
|
|
67
66
|
}>;
|
|
68
67
|
/**
|
|
@@ -188,9 +187,9 @@ export type GotRequestFunction<U extends ExtendOptions = Record<string, unknown>
|
|
|
188
187
|
(options: OptionsOfTextResponseBodyOnly): RequestPromise<string>;
|
|
189
188
|
<T>(options: OptionsOfJSONResponseBodyOnly): RequestPromise<T>;
|
|
190
189
|
(options: OptionsOfBufferResponseBodyOnly): RequestPromise<Uint8Array<ArrayBuffer>>;
|
|
191
|
-
(url: string | URL, options?:
|
|
192
|
-
(options:
|
|
193
|
-
(url: undefined, options: undefined, defaults: Options): RequestPromise
|
|
190
|
+
(url: string | URL, options?: StreamOptions): RequestPromise;
|
|
191
|
+
(options: StreamOptions): RequestPromise;
|
|
192
|
+
(url: undefined, options: undefined, defaults: Options): RequestPromise;
|
|
194
193
|
};
|
|
195
194
|
/**
|
|
196
195
|
All available HTTP request methods provided by Got.
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -254,13 +254,11 @@ By default, Got will retry on failure. To disable this option, set [`options.ret
|
|
|
254
254
|
[s3]: https://www.npmjs.com/package/superagent
|
|
255
255
|
|
|
256
256
|
<!-- COVERAGE -->
|
|
257
|
-
[gc]: https://img.shields.io/coveralls/github/sindresorhus/got?color=0b9062&label
|
|
258
257
|
[kc]: https://img.shields.io/codecov/c/github/sindresorhus/ky?color=0b9062&label
|
|
259
258
|
[nc]: https://img.shields.io/coveralls/github/bitinn/node-fetch?color=0b9062&label
|
|
260
259
|
[ac]: https://img.shields.io/coveralls/github/mzabriskie/axios?color=0b9062&label
|
|
261
260
|
[sc]: https://img.shields.io/codecov/c/github/visionmedia/superagent?color=0b9062&label
|
|
262
261
|
|
|
263
|
-
[g4]: https://coveralls.io/github/sindresorhus/got
|
|
264
262
|
[k4]: https://codecov.io/gh/sindresorhus/ky
|
|
265
263
|
[n4]: https://coveralls.io/github/bitinn/node-fetch
|
|
266
264
|
[a4]: https://coveralls.io/github/mzabriskie/axios
|
|
@@ -342,7 +340,6 @@ By default, Got will retry on failure. To disable this option, set [`options.ret
|
|
|
342
340
|
[k10]: https://github.com/sindresorhus/ky
|
|
343
341
|
[n10]: https://github.com/node-fetch/node-fetch
|
|
344
342
|
[a10]: https://github.com/axios/axios
|
|
345
|
-
[s10]: https://github.com/visionmedia/superagent
|
|
346
343
|
|
|
347
344
|
<!-- LAST COMMIT -->
|
|
348
345
|
[glc]: https://img.shields.io/github/last-commit/sindresorhus/got?color=gray&label
|