got 14.2.0 → 14.3.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/as-promise/index.js +12 -6
- package/dist/source/core/calculate-retry-delay.d.ts +1 -1
- package/dist/source/core/index.js +3 -5
- package/dist/source/core/options.d.ts +2 -2
- package/dist/source/core/options.js +1 -1
- package/dist/source/core/utils/proxy-events.js +2 -2
- package/dist/source/core/utils/unhandle.d.ts +2 -2
- package/dist/source/core/utils/unhandle.js +3 -3
- package/dist/source/create.js +2 -6
- package/package.json +15 -15
- package/readme.md +8 -14
|
@@ -3,7 +3,7 @@ import is from '@sindresorhus/is';
|
|
|
3
3
|
import PCancelable from 'p-cancelable';
|
|
4
4
|
import { HTTPError, RetryError, } from '../core/errors.js';
|
|
5
5
|
import Request from '../core/index.js';
|
|
6
|
-
import { parseBody, isResponseOk } from '../core/response.js';
|
|
6
|
+
import { parseBody, isResponseOk, ParseError, } from '../core/response.js';
|
|
7
7
|
import proxyEvents from '../core/utils/proxy-events.js';
|
|
8
8
|
import { CancelError } from './types.js';
|
|
9
9
|
const proxiedRequestEvents = [
|
|
@@ -49,7 +49,13 @@ export default function asPromise(firstRequest) {
|
|
|
49
49
|
}
|
|
50
50
|
catch (error) {
|
|
51
51
|
// Fall back to `utf8`
|
|
52
|
-
|
|
52
|
+
try {
|
|
53
|
+
response.body = response.rawBody.toString();
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
request._beforeError(new ParseError(error, response));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
53
59
|
if (isResponseOk(response)) {
|
|
54
60
|
request._beforeError(error);
|
|
55
61
|
return;
|
|
@@ -124,12 +130,12 @@ export default function asPromise(firstRequest) {
|
|
|
124
130
|
};
|
|
125
131
|
makeRequest(0);
|
|
126
132
|
});
|
|
127
|
-
promise.on = (event,
|
|
128
|
-
emitter.on(event,
|
|
133
|
+
promise.on = (event, function_) => {
|
|
134
|
+
emitter.on(event, function_);
|
|
129
135
|
return promise;
|
|
130
136
|
};
|
|
131
|
-
promise.off = (event,
|
|
132
|
-
emitter.off(event,
|
|
137
|
+
promise.off = (event, function_) => {
|
|
138
|
+
emitter.off(event, function_);
|
|
133
139
|
return promise;
|
|
134
140
|
};
|
|
135
141
|
const shortcut = (responseType) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { RetryFunction } from './options.js';
|
|
2
|
-
type Returns<T extends (...
|
|
2
|
+
type Returns<T extends (...arguments_: any) => unknown, V> = (...arguments_: Parameters<T>) => V;
|
|
3
3
|
declare const calculateRetryDelay: Returns<RetryFunction, number>;
|
|
4
4
|
export default calculateRetryDelay;
|
|
@@ -824,9 +824,7 @@ export default class Request extends Duplex {
|
|
|
824
824
|
break;
|
|
825
825
|
}
|
|
826
826
|
}
|
|
827
|
-
|
|
828
|
-
request = options.getRequestFunction();
|
|
829
|
-
}
|
|
827
|
+
request ||= options.getRequestFunction();
|
|
830
828
|
const url = options.url;
|
|
831
829
|
this._requestOptions = options.createNativeRequestOptions();
|
|
832
830
|
if (options.cache) {
|
|
@@ -836,11 +834,11 @@ export default class Request extends Duplex {
|
|
|
836
834
|
this._prepareCache(options.cache);
|
|
837
835
|
}
|
|
838
836
|
// Cache support
|
|
839
|
-
const
|
|
837
|
+
const function_ = options.cache ? this._createCacheableRequest : request;
|
|
840
838
|
try {
|
|
841
839
|
// We can't do `await fn(...)`,
|
|
842
840
|
// because stream `error` event can be emitted before `Promise.resolve()`.
|
|
843
|
-
let requestOrResponse =
|
|
841
|
+
let requestOrResponse = function_(url, this._requestOptions);
|
|
844
842
|
if (is.promise(requestOrResponse)) {
|
|
845
843
|
requestOrResponse = await requestOrResponse;
|
|
846
844
|
}
|
|
@@ -38,8 +38,8 @@ export type Agents = {
|
|
|
38
38
|
};
|
|
39
39
|
export type Headers = Record<string, string | string[] | undefined>;
|
|
40
40
|
export type ToughCookieJar = {
|
|
41
|
-
getCookieString: ((currentUrl: string, options: Record<string, unknown>,
|
|
42
|
-
setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record<string, unknown>,
|
|
41
|
+
getCookieString: ((currentUrl: string, options: Record<string, unknown>, callback: (error: Error | null, cookies: string) => void) => void) & ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void);
|
|
42
|
+
setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record<string, unknown>, callback: (error: Error | null, cookie: unknown) => void) => void) & ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void);
|
|
43
43
|
};
|
|
44
44
|
export type PromiseCookieJar = {
|
|
45
45
|
getCookieString: (url: string) => Promise<string>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export default function proxyEvents(from, to, events) {
|
|
2
2
|
const eventFunctions = {};
|
|
3
3
|
for (const event of events) {
|
|
4
|
-
const eventFunction = (...
|
|
5
|
-
to.emit(event, ...
|
|
4
|
+
const eventFunction = (...arguments_) => {
|
|
5
|
+
to.emit(event, ...arguments_);
|
|
6
6
|
};
|
|
7
7
|
eventFunctions[event] = eventFunction;
|
|
8
8
|
from.on(event, eventFunction);
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import type { EventEmitter } from 'node:events';
|
|
3
3
|
type Origin = EventEmitter;
|
|
4
4
|
type Event = string | symbol;
|
|
5
|
-
type
|
|
5
|
+
type AnyFunction = (...arguments_: any[]) => void;
|
|
6
6
|
type Unhandler = {
|
|
7
|
-
once: (origin: Origin, event: Event,
|
|
7
|
+
once: (origin: Origin, event: Event, function_: AnyFunction) => void;
|
|
8
8
|
unhandleAll: () => void;
|
|
9
9
|
};
|
|
10
10
|
export default function unhandle(): Unhandler;
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
export default function unhandle() {
|
|
6
6
|
const handlers = [];
|
|
7
7
|
return {
|
|
8
|
-
once(origin, event,
|
|
9
|
-
origin.once(event,
|
|
10
|
-
handlers.push({ origin, event, fn });
|
|
8
|
+
once(origin, event, function_) {
|
|
9
|
+
origin.once(event, function_);
|
|
10
|
+
handlers.push({ origin, event, fn: function_ });
|
|
11
11
|
},
|
|
12
12
|
unhandleAll() {
|
|
13
13
|
for (const handler of handlers) {
|
package/dist/source/create.js
CHANGED
|
@@ -38,9 +38,7 @@ const create = (defaults) => {
|
|
|
38
38
|
if (normalized.isStream) {
|
|
39
39
|
return request;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
promise = asPromise(request);
|
|
43
|
-
}
|
|
41
|
+
promise ||= asPromise(request);
|
|
44
42
|
return promise;
|
|
45
43
|
};
|
|
46
44
|
let iteration = 0;
|
|
@@ -48,9 +46,7 @@ const create = (defaults) => {
|
|
|
48
46
|
const handler = defaults.handlers[iteration++] ?? lastHandler;
|
|
49
47
|
const result = handler(newOptions, iterateHandlers);
|
|
50
48
|
if (is.promise(result) && !request.options.isStream) {
|
|
51
|
-
|
|
52
|
-
promise = asPromise(request);
|
|
53
|
-
}
|
|
49
|
+
promise ||= asPromise(request);
|
|
54
50
|
if (result !== promise) {
|
|
55
51
|
const descriptors = Object.getOwnPropertyDescriptors(promise);
|
|
56
52
|
for (const key in descriptors) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "got",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.3.0",
|
|
4
4
|
"description": "Human-friendly and powerful HTTP request library for Node.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/got",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"ky"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@sindresorhus/is": "^6.1
|
|
51
|
+
"@sindresorhus/is": "^6.3.1",
|
|
52
52
|
"@szmarczak/http-timer": "^5.0.1",
|
|
53
53
|
"cacheable-lookup": "^7.0.0",
|
|
54
|
-
"cacheable-request": "^
|
|
54
|
+
"cacheable-request": "^12.0.1",
|
|
55
55
|
"decompress-response": "^6.0.0",
|
|
56
56
|
"form-data-encoder": "^4.0.2",
|
|
57
57
|
"get-stream": "^8.0.1",
|
|
@@ -66,14 +66,14 @@
|
|
|
66
66
|
"@sinonjs/fake-timers": "^11.2.2",
|
|
67
67
|
"@types/benchmark": "^2.1.5",
|
|
68
68
|
"@types/express": "^4.17.21",
|
|
69
|
-
"@types/node": "^20.
|
|
69
|
+
"@types/node": "^20.12.12",
|
|
70
70
|
"@types/pem": "^1.14.4",
|
|
71
|
-
"@types/readable-stream": "^4.0.
|
|
71
|
+
"@types/readable-stream": "^4.0.14",
|
|
72
72
|
"@types/request": "^2.48.12",
|
|
73
73
|
"@types/sinon": "^17.0.2",
|
|
74
74
|
"@types/sinonjs__fake-timers": "^8.1.5",
|
|
75
75
|
"ava": "^5.3.1",
|
|
76
|
-
"axios": "^1.6.
|
|
76
|
+
"axios": "^1.6.8",
|
|
77
77
|
"benchmark": "^2.1.4",
|
|
78
78
|
"bluebird": "^3.7.2",
|
|
79
79
|
"body-parser": "^1.20.2",
|
|
@@ -81,33 +81,33 @@
|
|
|
81
81
|
"create-test-server": "^3.0.1",
|
|
82
82
|
"del-cli": "^5.1.0",
|
|
83
83
|
"delay": "^6.0.0",
|
|
84
|
-
"express": "^4.
|
|
84
|
+
"express": "^4.19.2",
|
|
85
85
|
"form-data": "^4.0.0",
|
|
86
86
|
"formdata-node": "^6.0.3",
|
|
87
|
-
"nock": "^13.4
|
|
87
|
+
"nock": "^13.5.4",
|
|
88
88
|
"node-fetch": "^3.3.2",
|
|
89
|
-
"np": "^
|
|
89
|
+
"np": "^10.0.5",
|
|
90
90
|
"nyc": "^15.1.0",
|
|
91
|
-
"p-event": "^6.0.
|
|
91
|
+
"p-event": "^6.0.1",
|
|
92
92
|
"pem": "^1.14.8",
|
|
93
93
|
"pify": "^6.1.0",
|
|
94
94
|
"readable-stream": "^4.4.2",
|
|
95
95
|
"request": "^2.88.2",
|
|
96
|
-
"sinon": "^
|
|
96
|
+
"sinon": "^18.0.0",
|
|
97
97
|
"slow-stream": "0.0.4",
|
|
98
98
|
"tempy": "^3.1.0",
|
|
99
99
|
"then-busboy": "^5.2.1",
|
|
100
|
-
"tough-cookie": "^4.1.
|
|
101
|
-
"tsx": "^4.
|
|
100
|
+
"tough-cookie": "^4.1.4",
|
|
101
|
+
"tsx": "^4.10.4",
|
|
102
102
|
"type-fest": "^4.8.2",
|
|
103
|
-
"typescript": "^5.
|
|
103
|
+
"typescript": "^5.4.5",
|
|
104
104
|
"xo": "^0.56.0"
|
|
105
105
|
},
|
|
106
106
|
"ava": {
|
|
107
107
|
"files": [
|
|
108
108
|
"test/*"
|
|
109
109
|
],
|
|
110
|
-
"timeout": "
|
|
110
|
+
"timeout": "10m",
|
|
111
111
|
"extensions": {
|
|
112
112
|
"ts": "module"
|
|
113
113
|
},
|
package/readme.md
CHANGED
|
@@ -12,11 +12,13 @@
|
|
|
12
12
|
</sup>
|
|
13
13
|
</p>
|
|
14
14
|
<br>
|
|
15
|
+
<br>
|
|
15
16
|
<a href="https://retool.com/?utm_campaign=sindresorhus">
|
|
16
|
-
<img src="https://sindresorhus.com/assets/thanks/retool-logo.svg" width="
|
|
17
|
+
<img src="https://sindresorhus.com/assets/thanks/retool-logo.svg" width="220">
|
|
17
18
|
</a>
|
|
18
19
|
<br>
|
|
19
20
|
<br>
|
|
21
|
+
<br>
|
|
20
22
|
<a href="https://strapi.io/?ref=sindresorhus">
|
|
21
23
|
<div>
|
|
22
24
|
<img src="https://sindresorhus.com/assets/thanks/strapi-logo-white-bg.png" width="200" alt="Strapi">
|
|
@@ -45,26 +47,18 @@
|
|
|
45
47
|
<br>
|
|
46
48
|
<br>
|
|
47
49
|
<br>
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
</div>
|
|
52
|
-
<br>
|
|
53
|
-
<b>VPS hosting with taste 😛</b>
|
|
50
|
+
<br>
|
|
51
|
+
<a href="https://www.fame.fi#gh-light-mode-only">
|
|
52
|
+
<img src="https://sindresorhus.com/assets/thanks/fame-logo-light.svg" width="200" alt="Fame Helsinki">
|
|
54
53
|
</a>
|
|
55
|
-
<a href="https://
|
|
56
|
-
<
|
|
57
|
-
<img src="https://sindresorhus.com/assets/thanks/dutchis-logo-dark.png" width="200" alt="DutchIS">
|
|
58
|
-
</div>
|
|
59
|
-
<br>
|
|
60
|
-
<b>VPS hosting with taste 😛</b>
|
|
54
|
+
<a href="https://www.fame.fi#gh-dark-mode-only">
|
|
55
|
+
<img src="https://sindresorhus.com/assets/thanks/fame-logo-dark.svg" width="200" alt="Fame Helsinki">
|
|
61
56
|
</a>
|
|
62
57
|
<br>
|
|
63
58
|
<br>
|
|
64
59
|
<br>
|
|
65
60
|
<br>
|
|
66
61
|
<br>
|
|
67
|
-
<br>
|
|
68
62
|
</p>
|
|
69
63
|
<br>
|
|
70
64
|
<br>
|