got 12.6.1 → 13.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/dist/source/core/index.d.ts +1 -2
- package/dist/source/core/index.js +6 -5
- package/dist/source/core/options.d.ts +4 -7
- package/dist/source/core/options.js +7 -7
- package/dist/source/core/response.d.ts +0 -1
- package/dist/source/core/timed-out.js +9 -9
- package/dist/source/core/utils/is-unix-socket-url.d.ts +0 -1
- package/dist/source/core/utils/options-to-url.d.ts +0 -1
- package/dist/source/core/utils/options-to-url.js +0 -2
- package/dist/source/core/utils/url-to-options.d.ts +1 -1
- package/dist/source/types.d.ts +0 -1
- package/package.json +10 -9
- package/readme.md +3 -3
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
/// <reference types="node" resolution-mode="require"/>
|
|
5
5
|
/// <reference types="node" resolution-mode="require"/>
|
|
6
6
|
import { Duplex } from 'node:stream';
|
|
7
|
-
import { URL } from 'node:url';
|
|
8
7
|
import type { ClientRequest } from 'node:http';
|
|
9
8
|
import type { Socket } from 'node:net';
|
|
10
9
|
import type { Timings } from '@szmarczak/http-timer';
|
|
@@ -107,7 +106,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
|
|
|
107
106
|
private _isFromCache?;
|
|
108
107
|
private _cannotHaveBody;
|
|
109
108
|
private _triggerRead;
|
|
110
|
-
private _jobs;
|
|
109
|
+
private readonly _jobs;
|
|
111
110
|
private _cancelTimeouts;
|
|
112
111
|
private readonly _removeListeners;
|
|
113
112
|
private _nativeResponse?;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
3
|
import { Duplex } from 'node:stream';
|
|
4
|
-
import { URL, URLSearchParams } from 'node:url';
|
|
5
4
|
import http, { ServerResponse } from 'node:http';
|
|
6
5
|
import timer from '@szmarczak/http-timer';
|
|
7
6
|
import CacheableRequest, { CacheError as CacheableCacheError, } from 'cacheable-request';
|
|
@@ -21,7 +20,7 @@ import { isResponseOk } from './response.js';
|
|
|
21
20
|
import isClientRequest from './utils/is-client-request.js';
|
|
22
21
|
import isUnixSocketURL from './utils/is-unix-socket-url.js';
|
|
23
22
|
import { RequestError, ReadError, MaxRedirectsError, HTTPError, TimeoutError, UploadError, CacheError, AbortError, } from './errors.js';
|
|
24
|
-
const { buffer:
|
|
23
|
+
const { buffer: getStreamAsBuffer } = getStream;
|
|
25
24
|
const supportsBrotli = is.string(process.versions.brotli);
|
|
26
25
|
const methodsWithoutBody = new Set(['GET', 'HEAD']);
|
|
27
26
|
const cacheableStore = new WeakableMap();
|
|
@@ -268,7 +267,7 @@ export default class Request extends Duplex {
|
|
|
268
267
|
else {
|
|
269
268
|
this.options.signal.addEventListener('abort', abort);
|
|
270
269
|
this._removeListeners = () => {
|
|
271
|
-
this.options.signal
|
|
270
|
+
this.options.signal?.removeEventListener('abort', abort);
|
|
272
271
|
};
|
|
273
272
|
}
|
|
274
273
|
}
|
|
@@ -750,7 +749,10 @@ export default class Request extends Duplex {
|
|
|
750
749
|
}
|
|
751
750
|
try {
|
|
752
751
|
// Errors are emitted via the `error` event
|
|
753
|
-
const rawBody = await
|
|
752
|
+
const rawBody = await getStreamAsBuffer(from);
|
|
753
|
+
// TODO: Switch to this:
|
|
754
|
+
// let rawBody = await from.toArray();
|
|
755
|
+
// rawBody = Buffer.concat(rawBody);
|
|
754
756
|
// On retry Request is destroyed with no error, therefore the above will successfully resolve.
|
|
755
757
|
// So in order to check if this was really successfull, we need to check if it has been properly ended.
|
|
756
758
|
if (!this.isAborted) {
|
|
@@ -844,7 +846,6 @@ export default class Request extends Duplex {
|
|
|
844
846
|
// We only need to implement the error handler in order to support HTTP2 caching.
|
|
845
847
|
// The result will be a promise anyway.
|
|
846
848
|
// @ts-expect-error ignore
|
|
847
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
848
849
|
result.once = (event, handler) => {
|
|
849
850
|
if (event === 'error') {
|
|
850
851
|
(async () => {
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
/// <reference types="node" resolution-mode="require"/>
|
|
9
9
|
/// <reference types="node" resolution-mode="require"/>
|
|
10
10
|
import type { Buffer } from 'node:buffer';
|
|
11
|
-
import { URL, URLSearchParams } from 'node:url';
|
|
12
11
|
import { checkServerIdentity } from 'node:tls';
|
|
13
12
|
import http from 'node:http';
|
|
14
13
|
import https from 'node:https';
|
|
@@ -567,7 +566,7 @@ export type OptionsInit = Except<Partial<InternalsType>, 'hooks' | 'retry'> & {
|
|
|
567
566
|
};
|
|
568
567
|
export default class Options {
|
|
569
568
|
private _unixOptions?;
|
|
570
|
-
private _internals;
|
|
569
|
+
private readonly _internals;
|
|
571
570
|
private _merging;
|
|
572
571
|
private readonly _init;
|
|
573
572
|
constructor(input?: string | URL | OptionsInit, options?: OptionsInit, defaults?: Options);
|
|
@@ -741,8 +740,6 @@ export default class Options {
|
|
|
741
740
|
/**
|
|
742
741
|
You can abort the `request` using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
|
|
743
742
|
|
|
744
|
-
*Requires Node.js 16 or later.*
|
|
745
|
-
|
|
746
743
|
@example
|
|
747
744
|
```
|
|
748
745
|
import got from 'got';
|
|
@@ -758,8 +755,8 @@ export default class Options {
|
|
|
758
755
|
}, 100);
|
|
759
756
|
```
|
|
760
757
|
*/
|
|
761
|
-
get signal():
|
|
762
|
-
set signal(value:
|
|
758
|
+
get signal(): AbortSignal | undefined;
|
|
759
|
+
set signal(value: AbortSignal | undefined);
|
|
763
760
|
/**
|
|
764
761
|
Ignore invalid cookies instead of throwing an error.
|
|
765
762
|
Only useful when the `cookieJar` option has been set. Not recommended.
|
|
@@ -1147,7 +1144,7 @@ export default class Options {
|
|
|
1147
1144
|
form: Record<string, any> | undefined;
|
|
1148
1145
|
url: string | URL | undefined;
|
|
1149
1146
|
cookieJar: PromiseCookieJar | ToughCookieJar | undefined;
|
|
1150
|
-
signal:
|
|
1147
|
+
signal: AbortSignal | undefined;
|
|
1151
1148
|
ignoreInvalidCookies: boolean;
|
|
1152
1149
|
searchParams: string | SearchParameters | URLSearchParams | undefined;
|
|
1153
1150
|
dnsLookup: {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import { promisify, inspect } from 'node:util';
|
|
3
|
-
import { URL, URLSearchParams } from 'node:url';
|
|
4
3
|
import { checkServerIdentity } from 'node:tls';
|
|
5
4
|
// DO NOT use destructuring for `https.request` and `http.request` as it's not compatible with `nock`.
|
|
6
5
|
import http from 'node:http';
|
|
@@ -181,7 +180,7 @@ const defaultInternals = {
|
|
|
181
180
|
setHost: true,
|
|
182
181
|
maxHeaderSize: undefined,
|
|
183
182
|
signal: undefined,
|
|
184
|
-
enableUnixSockets:
|
|
183
|
+
enableUnixSockets: false,
|
|
185
184
|
};
|
|
186
185
|
const cloneInternals = (internals) => {
|
|
187
186
|
const { hooks, retry } = internals;
|
|
@@ -408,7 +407,12 @@ export default class Options {
|
|
|
408
407
|
throw new Error(`Unexpected option: ${key}`);
|
|
409
408
|
}
|
|
410
409
|
// @ts-expect-error Type 'unknown' is not assignable to type 'never'.
|
|
411
|
-
|
|
410
|
+
const value = options[key];
|
|
411
|
+
if (value === undefined) {
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
// @ts-expect-error Type 'unknown' is not assignable to type 'never'.
|
|
415
|
+
this[key] = value;
|
|
412
416
|
push = true;
|
|
413
417
|
}
|
|
414
418
|
if (push) {
|
|
@@ -764,8 +768,6 @@ export default class Options {
|
|
|
764
768
|
/**
|
|
765
769
|
You can abort the `request` using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
|
|
766
770
|
|
|
767
|
-
*Requires Node.js 16 or later.*
|
|
768
|
-
|
|
769
771
|
@example
|
|
770
772
|
```
|
|
771
773
|
import got from 'got';
|
|
@@ -781,11 +783,9 @@ export default class Options {
|
|
|
781
783
|
}, 100);
|
|
782
784
|
```
|
|
783
785
|
*/
|
|
784
|
-
// TODO: Replace `any` with `AbortSignal` when targeting Node 16.
|
|
785
786
|
get signal() {
|
|
786
787
|
return this._internals.signal;
|
|
787
788
|
}
|
|
788
|
-
// TODO: Replace `any` with `AbortSignal` when targeting Node 16.
|
|
789
789
|
set signal(value) {
|
|
790
790
|
assert.object(value);
|
|
791
791
|
this._internals.signal = value;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import type { Buffer } from 'node:buffer';
|
|
4
|
-
import type { URL } from 'node:url';
|
|
5
4
|
import type { IncomingMessageWithTimings, Timings } from '@szmarczak/http-timer';
|
|
6
5
|
import { RequestError } from './errors.js';
|
|
7
6
|
import type { ParseJsonFunction, ResponseType } from './options.js';
|
|
@@ -55,13 +55,13 @@ export default function timedOut(request, delays, options) {
|
|
|
55
55
|
throw error;
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
|
-
if (
|
|
58
|
+
if (delays.request !== undefined) {
|
|
59
59
|
const cancelTimeout = addTimeout(delays.request, timeoutHandler, 'request');
|
|
60
60
|
once(request, 'response', (response) => {
|
|
61
61
|
once(response, 'end', cancelTimeout);
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
-
if (
|
|
64
|
+
if (delays.socket !== undefined) {
|
|
65
65
|
const { socket } = delays;
|
|
66
66
|
const socketTimeoutHandler = () => {
|
|
67
67
|
timeoutHandler(socket, 'socket');
|
|
@@ -74,17 +74,17 @@ export default function timedOut(request, delays, options) {
|
|
|
74
74
|
request.removeListener('timeout', socketTimeoutHandler);
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
const hasLookup =
|
|
78
|
-
const hasConnect =
|
|
79
|
-
const hasSecureConnect =
|
|
80
|
-
const hasSend =
|
|
77
|
+
const hasLookup = delays.lookup !== undefined;
|
|
78
|
+
const hasConnect = delays.connect !== undefined;
|
|
79
|
+
const hasSecureConnect = delays.secureConnect !== undefined;
|
|
80
|
+
const hasSend = delays.send !== undefined;
|
|
81
81
|
if (hasLookup || hasConnect || hasSecureConnect || hasSend) {
|
|
82
82
|
once(request, 'socket', (socket) => {
|
|
83
83
|
const { socketPath } = request;
|
|
84
84
|
/* istanbul ignore next: hard to test */
|
|
85
85
|
if (socket.connecting) {
|
|
86
86
|
const hasPath = Boolean(socketPath ?? net.isIP(hostname ?? host ?? '') !== 0);
|
|
87
|
-
if (hasLookup && !hasPath &&
|
|
87
|
+
if (hasLookup && !hasPath && socket.address().address === undefined) {
|
|
88
88
|
const cancelTimeout = addTimeout(delays.lookup, timeoutHandler, 'lookup');
|
|
89
89
|
once(socket, 'lookup', cancelTimeout);
|
|
90
90
|
}
|
|
@@ -122,13 +122,13 @@ export default function timedOut(request, delays, options) {
|
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
|
-
if (
|
|
125
|
+
if (delays.response !== undefined) {
|
|
126
126
|
once(request, 'upload-complete', () => {
|
|
127
127
|
const cancelTimeout = addTimeout(delays.response, timeoutHandler, 'response');
|
|
128
128
|
once(request, 'response', cancelTimeout);
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
-
if (
|
|
131
|
+
if (delays.read !== undefined) {
|
|
132
132
|
once(request, 'response', (response) => {
|
|
133
133
|
const cancelTimeout = addTimeout(delays.read, timeoutHandler, 'read');
|
|
134
134
|
once(response, 'end', cancelTimeout);
|
package/dist/source/types.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import type { Buffer } from 'node:buffer';
|
|
4
|
-
import type { URL } from 'node:url';
|
|
5
4
|
import type { CancelableRequest } from './as-promise/types.js';
|
|
6
5
|
import type { Response } from './core/response.js';
|
|
7
6
|
import type Options from './core/options.js';
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "got",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0",
|
|
4
4
|
"description": "Human-friendly and powerful HTTP request library for Node.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/got",
|
|
7
7
|
"funding": "https://github.com/sindresorhus/got?sponsor=1",
|
|
8
8
|
"type": "module",
|
|
9
|
-
"exports":
|
|
10
|
-
|
|
9
|
+
"exports": {
|
|
10
|
+
"types": "./dist/source/index.d.ts",
|
|
11
|
+
"default": "./dist/source/index.js"
|
|
12
|
+
},
|
|
11
13
|
"engines": {
|
|
12
|
-
"node": ">=
|
|
14
|
+
"node": ">=16"
|
|
13
15
|
},
|
|
14
16
|
"scripts": {
|
|
15
17
|
"test": "xo && tsc --noEmit && ava",
|
|
@@ -99,8 +101,8 @@
|
|
|
99
101
|
"tough-cookie": "4.1.2",
|
|
100
102
|
"ts-node": "^10.8.2",
|
|
101
103
|
"type-fest": "^3.6.1",
|
|
102
|
-
"typescript": "
|
|
103
|
-
"xo": "^0.
|
|
104
|
+
"typescript": "^5.0.4",
|
|
105
|
+
"xo": "^0.54.2"
|
|
104
106
|
},
|
|
105
107
|
"sideEffects": false,
|
|
106
108
|
"ava": {
|
|
@@ -135,10 +137,7 @@
|
|
|
135
137
|
"rules": {
|
|
136
138
|
"@typescript-eslint/no-empty-function": "off",
|
|
137
139
|
"n/no-deprecated-api": "off",
|
|
138
|
-
"n/prefer-global/url": "off",
|
|
139
|
-
"n/prefer-global/url-search-params": "off",
|
|
140
140
|
"@typescript-eslint/no-implicit-any-catch": "off",
|
|
141
|
-
"unicorn/prefer-node-protocol": "off",
|
|
142
141
|
"ava/assertion-arguments": "off",
|
|
143
142
|
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
144
143
|
"@typescript-eslint/no-unsafe-return": "off",
|
|
@@ -146,6 +145,8 @@
|
|
|
146
145
|
"@typescript-eslint/no-unsafe-call": "off",
|
|
147
146
|
"@typescript-eslint/await-thenable": "off",
|
|
148
147
|
"@typescript-eslint/no-redundant-type-constituents": "off",
|
|
148
|
+
"@typescript-eslint/no-unsafe-argument": "off",
|
|
149
|
+
"@typescript-eslint/promise-function-async": "off",
|
|
149
150
|
"no-lone-blocks": "off",
|
|
150
151
|
"unicorn/no-await-expression-member": "off"
|
|
151
152
|
}
|
package/readme.md
CHANGED
|
@@ -94,7 +94,7 @@ npm install got
|
|
|
94
94
|
|
|
95
95
|
**Warning:** This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and no longer provides a CommonJS export. If your project uses CommonJS, you will have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) or use the [dynamic `import()`](https://v8.dev/features/dynamic-import) function. Please don't open issues for questions regarding CommonJS / ESM.
|
|
96
96
|
|
|
97
|
-
**Got v11
|
|
97
|
+
**Got v11 is no longer maintained and we will not accept any backport requests.**
|
|
98
98
|
|
|
99
99
|
## Take a peek
|
|
100
100
|
|
|
@@ -203,7 +203,7 @@ By default, Got will retry on failure. To disable this option, set [`options.ret
|
|
|
203
203
|
| Pagination API | :heavy_check_mark: | :x: | :x: | :x: | :x: |
|
|
204
204
|
| Request cancelation | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
|
205
205
|
| RFC compliant caching | :heavy_check_mark: | :x: | :x: | :x: | :x: |
|
|
206
|
-
| Cookies (out-of-box) | :heavy_check_mark: | :x: | :x: | :x: | :x: |
|
|
206
|
+
| Cookies (out-of-the-box) | :heavy_check_mark: | :x: | :x: | :x: | :x: |
|
|
207
207
|
| Follows redirects | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
|
208
208
|
| Retries on failure | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: |
|
|
209
209
|
| Progress events | :heavy_check_mark: | :x: | :heavy_check_mark:\*\*\* | Browser only | :heavy_check_mark: |
|
|
@@ -436,7 +436,7 @@ By default, Got will retry on failure. To disable this option, set [`options.ret
|
|
|
436
436
|
</td>
|
|
437
437
|
<td align="center">
|
|
438
438
|
<a href="https://github.com/renovatebot/renovate">
|
|
439
|
-
<img width="150" valign="middle" src="https://camo.githubusercontent.com/
|
|
439
|
+
<img width="150" valign="middle" src="https://camo.githubusercontent.com/7c2dc41a8407d4cfa700f762a1abf46b232858ae7e3a2bf5aee7d9f36416127c/68747470733a2f2f6170702e72656e6f76617465626f742e636f6d2f696d616765732f72656e6f766174655f3636305f3232302e6a7067">
|
|
440
440
|
</a>
|
|
441
441
|
</td>
|
|
442
442
|
<td align="center">
|