got 12.4.1 → 12.5.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.
|
@@ -3,16 +3,12 @@
|
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
/// <reference types="node" />
|
|
5
5
|
/// <reference types="node" />
|
|
6
|
-
/// <reference types="node" />
|
|
7
6
|
import { Duplex } from 'node:stream';
|
|
8
7
|
import { URL } from 'node:url';
|
|
9
|
-
import { ServerResponse } from 'node:http';
|
|
10
8
|
import type { ClientRequest } from 'node:http';
|
|
11
9
|
import type { Socket } from 'node:net';
|
|
12
|
-
import CacheableRequest from 'cacheable-request';
|
|
13
10
|
import type { Timings } from '@szmarczak/http-timer';
|
|
14
|
-
import
|
|
15
|
-
import Options, { type NativeRequestOptions } from './options.js';
|
|
11
|
+
import Options from './options.js';
|
|
16
12
|
import { type PlainResponse, type Response } from './response.js';
|
|
17
13
|
import { RequestError } from './errors.js';
|
|
18
14
|
declare type Error = NodeJS.ErrnoException;
|
|
@@ -87,7 +83,6 @@ export declare type RequestEvents<T> = {
|
|
|
87
83
|
once: GotEventFunction<T>;
|
|
88
84
|
off: GotEventFunction<T>;
|
|
89
85
|
};
|
|
90
|
-
export declare type CacheableRequestFunction = (options: string | URL | NativeRequestOptions, cb?: (response: ServerResponse | ResponseLike) => void) => CacheableRequest.Emitter;
|
|
91
86
|
declare type UrlType = ConstructorParameters<typeof Options>[0];
|
|
92
87
|
declare type OptionsType = ConstructorParameters<typeof Options>[1];
|
|
93
88
|
declare type DefaultsType = ConstructorParameters<typeof Options>[2];
|
|
@@ -4,7 +4,7 @@ import { Duplex } from 'node:stream';
|
|
|
4
4
|
import { URL, URLSearchParams } from 'node:url';
|
|
5
5
|
import http, { ServerResponse } from 'node:http';
|
|
6
6
|
import timer from '@szmarczak/http-timer';
|
|
7
|
-
import CacheableRequest from 'cacheable-request';
|
|
7
|
+
import CacheableRequest, { CacheError as CacheableCacheError, } from 'cacheable-request';
|
|
8
8
|
import decompressResponse from 'decompress-response';
|
|
9
9
|
import is from '@sindresorhus/is';
|
|
10
10
|
import { buffer as getBuffer } from 'get-stream';
|
|
@@ -431,7 +431,6 @@ export default class Request extends Duplex {
|
|
|
431
431
|
if (this._request._writableState?.errored) {
|
|
432
432
|
return;
|
|
433
433
|
}
|
|
434
|
-
// The `!destroyed` check is required to prevent `uploadProgress` being emitted after the stream was destroyed
|
|
435
434
|
if (!error) {
|
|
436
435
|
this._bodySize = this._uploadedSize;
|
|
437
436
|
this.emit('uploadProgress', this.uploadProgress);
|
|
@@ -628,10 +627,10 @@ export default class Request extends Duplex {
|
|
|
628
627
|
}
|
|
629
628
|
this._request = undefined;
|
|
630
629
|
const updatedOptions = new Options(undefined, undefined, this.options);
|
|
631
|
-
const
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
630
|
+
const serverRequestedGet = statusCode === 303 && updatedOptions.method !== 'GET' && updatedOptions.method !== 'HEAD';
|
|
631
|
+
const canRewrite = statusCode !== 307 && statusCode !== 308;
|
|
632
|
+
const userRequestedGet = updatedOptions.methodRewriting && canRewrite;
|
|
633
|
+
if (serverRequestedGet || userRequestedGet) {
|
|
635
634
|
updatedOptions.method = 'GET';
|
|
636
635
|
updatedOptions.body = undefined;
|
|
637
636
|
updatedOptions.json = undefined;
|
|
@@ -821,7 +820,7 @@ export default class Request extends Duplex {
|
|
|
821
820
|
}
|
|
822
821
|
_prepareCache(cache) {
|
|
823
822
|
if (!cacheableStore.has(cache)) {
|
|
824
|
-
|
|
823
|
+
const cacheableRequest = new CacheableRequest(((requestOptions, handler) => {
|
|
825
824
|
const result = requestOptions._request(requestOptions, handler);
|
|
826
825
|
// TODO: remove this when `cacheable-request` supports async request functions.
|
|
827
826
|
if (is.promise(result)) {
|
|
@@ -859,7 +858,8 @@ export default class Request extends Duplex {
|
|
|
859
858
|
};
|
|
860
859
|
}
|
|
861
860
|
return result;
|
|
862
|
-
}), cache)
|
|
861
|
+
}), cache);
|
|
862
|
+
cacheableStore.set(cache, cacheableRequest.request());
|
|
863
863
|
}
|
|
864
864
|
}
|
|
865
865
|
async _createCacheableRequest(url, options) {
|
|
@@ -968,7 +968,7 @@ export default class Request extends Duplex {
|
|
|
968
968
|
}
|
|
969
969
|
}
|
|
970
970
|
catch (error) {
|
|
971
|
-
if (error instanceof
|
|
971
|
+
if (error instanceof CacheableCacheError) {
|
|
972
972
|
throw new CacheError(error, this);
|
|
973
973
|
}
|
|
974
974
|
throw error;
|
|
@@ -20,7 +20,7 @@ import type { RequestOptions as HttpsRequestOptions, Agent as HttpsAgent } from
|
|
|
20
20
|
import CacheableLookup from 'cacheable-lookup';
|
|
21
21
|
import http2wrapper, { type ClientHttp2Session } from 'http2-wrapper';
|
|
22
22
|
import type { FormDataLike } from 'form-data-encoder';
|
|
23
|
-
import type
|
|
23
|
+
import type { StorageAdapter } from 'cacheable-request';
|
|
24
24
|
import type ResponseLike from 'responselike';
|
|
25
25
|
import type { IncomingMessageWithTimings } from '@szmarczak/http-timer';
|
|
26
26
|
import type { CancelableRequest } from '../as-promise/types.js';
|
|
@@ -847,7 +847,7 @@ export default class Options {
|
|
|
847
847
|
Defines if redirect responses should be followed automatically.
|
|
848
848
|
|
|
849
849
|
Note that if a `303` is sent by the server in response to any request type (`POST`, `DELETE`, etc.), Got will automatically request the resource pointed to in the location header via `GET`.
|
|
850
|
-
This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4).
|
|
850
|
+
This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4). You can optionally turn on this behavior also for other redirect codes - see `methodRewriting`.
|
|
851
851
|
|
|
852
852
|
@default true
|
|
853
853
|
*/
|
|
@@ -867,8 +867,8 @@ export default class Options {
|
|
|
867
867
|
|
|
868
868
|
@default false
|
|
869
869
|
*/
|
|
870
|
-
get cache(): string |
|
|
871
|
-
set cache(value: string |
|
|
870
|
+
get cache(): string | StorageAdapter | boolean | undefined;
|
|
871
|
+
set cache(value: string | StorageAdapter | boolean | undefined);
|
|
872
872
|
/**
|
|
873
873
|
Determines if a `got.HTTPError` is thrown for unsuccessful responses.
|
|
874
874
|
|
|
@@ -911,7 +911,7 @@ export default class Options {
|
|
|
911
911
|
However, the [HTTP/2 specification](https://tools.ietf.org/html/rfc7540#section-8.1.3) says that `An HTTP GET request includes request header fields and no payload body`, therefore when using the HTTP/2 protocol this option will have no effect.
|
|
912
912
|
This option is only meant to interact with non-compliant servers when you have no other choice.
|
|
913
913
|
|
|
914
|
-
__Note__: The [RFC
|
|
914
|
+
__Note__: The [RFC 7231](https://tools.ietf.org/html/rfc7231#section-4.3.1) doesn't specify any particular behavior for the GET method having a payload, therefore __it's considered an [anti-pattern](https://en.wikipedia.org/wiki/Anti-pattern)__.
|
|
915
915
|
|
|
916
916
|
@default false
|
|
917
917
|
*/
|
|
@@ -927,9 +927,12 @@ export default class Options {
|
|
|
927
927
|
get headers(): Headers;
|
|
928
928
|
set headers(value: Headers);
|
|
929
929
|
/**
|
|
930
|
-
Specifies if the
|
|
930
|
+
Specifies if the HTTP request method should be [rewritten as `GET`](https://tools.ietf.org/html/rfc7231#section-6.4) on redirects.
|
|
931
931
|
|
|
932
|
-
|
|
932
|
+
As the [specification](https://tools.ietf.org/html/rfc7231#section-6.4) prefers to rewrite the HTTP method only on `303` responses, this is Got's default behavior.
|
|
933
|
+
Setting `methodRewriting` to `true` will also rewrite `301` and `302` responses, as allowed by the spec. This is the behavior followed by `curl` and browsers.
|
|
934
|
+
|
|
935
|
+
__Note__: Got never performs method rewriting on `307` and `308` responses, as this is [explicitly prohibited by the specification](https://www.rfc-editor.org/rfc/rfc7231#section-6.4.7).
|
|
933
936
|
|
|
934
937
|
@default false
|
|
935
938
|
*/
|
|
@@ -1160,7 +1163,7 @@ export default class Options {
|
|
|
1160
1163
|
hooks: Hooks;
|
|
1161
1164
|
followRedirect: boolean;
|
|
1162
1165
|
maxRedirects: number;
|
|
1163
|
-
cache: string | boolean |
|
|
1166
|
+
cache: string | boolean | StorageAdapter | undefined;
|
|
1164
1167
|
throwHttpErrors: boolean;
|
|
1165
1168
|
http2: boolean;
|
|
1166
1169
|
allowGetBody: boolean;
|
|
@@ -1004,7 +1004,7 @@ export default class Options {
|
|
|
1004
1004
|
Defines if redirect responses should be followed automatically.
|
|
1005
1005
|
|
|
1006
1006
|
Note that if a `303` is sent by the server in response to any request type (`POST`, `DELETE`, etc.), Got will automatically request the resource pointed to in the location header via `GET`.
|
|
1007
|
-
This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4).
|
|
1007
|
+
This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4). You can optionally turn on this behavior also for other redirect codes - see `methodRewriting`.
|
|
1008
1008
|
|
|
1009
1009
|
@default true
|
|
1010
1010
|
*/
|
|
@@ -1133,7 +1133,7 @@ export default class Options {
|
|
|
1133
1133
|
However, the [HTTP/2 specification](https://tools.ietf.org/html/rfc7540#section-8.1.3) says that `An HTTP GET request includes request header fields and no payload body`, therefore when using the HTTP/2 protocol this option will have no effect.
|
|
1134
1134
|
This option is only meant to interact with non-compliant servers when you have no other choice.
|
|
1135
1135
|
|
|
1136
|
-
__Note__: The [RFC
|
|
1136
|
+
__Note__: The [RFC 7231](https://tools.ietf.org/html/rfc7231#section-4.3.1) doesn't specify any particular behavior for the GET method having a payload, therefore __it's considered an [anti-pattern](https://en.wikipedia.org/wiki/Anti-pattern)__.
|
|
1137
1137
|
|
|
1138
1138
|
@default false
|
|
1139
1139
|
*/
|
|
@@ -1164,9 +1164,12 @@ export default class Options {
|
|
|
1164
1164
|
}
|
|
1165
1165
|
}
|
|
1166
1166
|
/**
|
|
1167
|
-
Specifies if the
|
|
1167
|
+
Specifies if the HTTP request method should be [rewritten as `GET`](https://tools.ietf.org/html/rfc7231#section-6.4) on redirects.
|
|
1168
1168
|
|
|
1169
|
-
|
|
1169
|
+
As the [specification](https://tools.ietf.org/html/rfc7231#section-6.4) prefers to rewrite the HTTP method only on `303` responses, this is Got's default behavior.
|
|
1170
|
+
Setting `methodRewriting` to `true` will also rewrite `301` and `302` responses, as allowed by the spec. This is the behavior followed by `curl` and browsers.
|
|
1171
|
+
|
|
1172
|
+
__Note__: Got never performs method rewriting on `307` and `308` responses, as this is [explicitly prohibited by the specification](https://www.rfc-editor.org/rfc/rfc7231#section-6.4.7).
|
|
1170
1173
|
|
|
1171
1174
|
@default false
|
|
1172
1175
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "got",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.5.0",
|
|
4
4
|
"description": "Human-friendly and powerful HTTP request library for Node.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/got",
|
|
@@ -47,11 +47,10 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@sindresorhus/is": "^5.2.0",
|
|
49
49
|
"@szmarczak/http-timer": "^5.0.1",
|
|
50
|
-
"@types/cacheable-request": "^6.0.2",
|
|
51
50
|
"cacheable-lookup": "^6.0.4",
|
|
52
|
-
"cacheable-request": "^
|
|
51
|
+
"cacheable-request": "^10.1.2",
|
|
53
52
|
"decompress-response": "^6.0.0",
|
|
54
|
-
"form-data-encoder": "^2.1.
|
|
53
|
+
"form-data-encoder": "^2.1.2",
|
|
55
54
|
"get-stream": "^6.0.1",
|
|
56
55
|
"http2-wrapper": "^2.1.10",
|
|
57
56
|
"lowercase-keys": "^3.0.0",
|
|
@@ -60,7 +59,7 @@
|
|
|
60
59
|
},
|
|
61
60
|
"devDependencies": {
|
|
62
61
|
"@hapi/bourne": "^3.0.0",
|
|
63
|
-
"@sindresorhus/tsconfig": "^
|
|
62
|
+
"@sindresorhus/tsconfig": "^3.0.1",
|
|
64
63
|
"@sinonjs/fake-timers": "^9.1.1",
|
|
65
64
|
"@types/benchmark": "^2.1.2",
|
|
66
65
|
"@types/express": "^4.17.13",
|
|
@@ -72,7 +71,7 @@
|
|
|
72
71
|
"@types/sinon": "^10.0.11",
|
|
73
72
|
"@types/sinonjs__fake-timers": "^8.1.1",
|
|
74
73
|
"@types/tough-cookie": "^4.0.1",
|
|
75
|
-
"ava": "^3.
|
|
74
|
+
"ava": "^4.3.3",
|
|
76
75
|
"axios": "^0.27.2",
|
|
77
76
|
"benchmark": "^2.1.4",
|
|
78
77
|
"bluebird": "^3.7.2",
|
|
@@ -83,7 +82,7 @@
|
|
|
83
82
|
"delay": "^5.0.0",
|
|
84
83
|
"express": "^4.17.3",
|
|
85
84
|
"form-data": "^4.0.0",
|
|
86
|
-
"formdata-node": "^
|
|
85
|
+
"formdata-node": "^5.0.0",
|
|
87
86
|
"nock": "^13.2.4",
|
|
88
87
|
"node-fetch": "^3.2.3",
|
|
89
88
|
"np": "^7.6.0",
|
|
@@ -96,10 +95,11 @@
|
|
|
96
95
|
"sinon": "^14.0.0",
|
|
97
96
|
"slow-stream": "0.0.4",
|
|
98
97
|
"tempy": "^3.0.0",
|
|
99
|
-
"then-busboy": "^5.
|
|
98
|
+
"then-busboy": "^5.2.1",
|
|
100
99
|
"to-readable-stream": "^3.0.0",
|
|
101
100
|
"tough-cookie": "4.0.0",
|
|
102
101
|
"ts-node": "^10.8.2",
|
|
102
|
+
"type-fest": "^2.19.0",
|
|
103
103
|
"typescript": "~4.8.2",
|
|
104
104
|
"xo": "^0.52.2"
|
|
105
105
|
},
|
|
@@ -109,10 +109,6 @@
|
|
|
109
109
|
"test/*"
|
|
110
110
|
],
|
|
111
111
|
"timeout": "1m",
|
|
112
|
-
"nonSemVerExperiments": {
|
|
113
|
-
"nextGenConfig": true,
|
|
114
|
-
"configurableModuleFormat": true
|
|
115
|
-
},
|
|
116
112
|
"extensions": {
|
|
117
113
|
"ts": "module"
|
|
118
114
|
},
|
package/readme.md
CHANGED
|
@@ -37,15 +37,6 @@
|
|
|
37
37
|
<br>
|
|
38
38
|
<br>
|
|
39
39
|
<br>
|
|
40
|
-
<a href="https://keygen.sh">
|
|
41
|
-
<div>
|
|
42
|
-
<img src="https://sindresorhus.com/assets/thanks/keygen-logo.svg" width="180" alt="Keygen">
|
|
43
|
-
</div>
|
|
44
|
-
<b>A dead-simple software licensing and distribution API built for developers</b>
|
|
45
|
-
</a>
|
|
46
|
-
<br>
|
|
47
|
-
<br>
|
|
48
|
-
<br>
|
|
49
40
|
<a href="https://www.useanvil.com/?utm_source=sindresorhus#gh-light-mode-only">
|
|
50
41
|
<div>
|
|
51
42
|
<img src="https://sindresorhus.com/assets/thanks/anvil-logo-light.svg" width="200" alt="Anvil">
|
|
@@ -76,6 +67,20 @@
|
|
|
76
67
|
</a>
|
|
77
68
|
<br>
|
|
78
69
|
<br>
|
|
70
|
+
<a href="https://sizzy.co/?utm_campaign=github_repo&utm_source=github&utm_medium=referral&utm_content=got&utm_term=sindre">
|
|
71
|
+
<div>
|
|
72
|
+
<img src="https://sindresorhus.com/assets/thanks/sizzy-logo.png" width="240" alt="Sizzy">
|
|
73
|
+
</div>
|
|
74
|
+
<div>
|
|
75
|
+
<sub>
|
|
76
|
+
<b>Before Sizzy:</b> web development is stressing you out, responsive design is hard, you have an overwhelming amount of opened tabs & apps.
|
|
77
|
+
<br>
|
|
78
|
+
<b>After Sizzy:</b> all the tools you need in one place, responsive design is a breeze, no more context switching.
|
|
79
|
+
</sub>
|
|
80
|
+
</div>
|
|
81
|
+
</a>
|
|
82
|
+
<br>
|
|
83
|
+
<br>
|
|
79
84
|
<br>
|
|
80
85
|
<br>
|
|
81
86
|
</p>
|