got 10.5.7 → 10.6.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-stream.js
CHANGED
|
@@ -21,7 +21,7 @@ function asStream(options) {
|
|
|
21
21
|
throw new Error('Got\'s stream is not writable when the `body`, `json` or `form` option is used');
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
else if (options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH') {
|
|
24
|
+
else if (options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH' || (options.allowGetBody && options.method === 'GET')) {
|
|
25
25
|
options.body = input;
|
|
26
26
|
}
|
|
27
27
|
else {
|
package/dist/source/index.js
CHANGED
|
@@ -193,6 +193,7 @@ exports.preNormalizeArguments = (options, defaults) => {
|
|
|
193
193
|
options.dnsCache = (_e = options.dnsCache, (_e !== null && _e !== void 0 ? _e : false));
|
|
194
194
|
options.useElectronNet = Boolean(options.useElectronNet);
|
|
195
195
|
options.methodRewriting = Boolean(options.methodRewriting);
|
|
196
|
+
options.allowGetBody = Boolean(options.allowGetBody);
|
|
196
197
|
options.context = (_f = options.context, (_f !== null && _f !== void 0 ? _f : {}));
|
|
197
198
|
return options;
|
|
198
199
|
};
|
|
@@ -305,7 +306,8 @@ exports.normalizeArguments = (url, options, defaults) => {
|
|
|
305
306
|
}
|
|
306
307
|
return normalizedOptions;
|
|
307
308
|
};
|
|
308
|
-
const withoutBody = new Set(['
|
|
309
|
+
const withoutBody = new Set(['HEAD']);
|
|
310
|
+
const withoutBodyUnlessSpecified = 'GET';
|
|
309
311
|
exports.normalizeRequestArguments = async (options) => {
|
|
310
312
|
var _a, _b, _c;
|
|
311
313
|
options = exports.mergeOptions(options);
|
|
@@ -320,6 +322,9 @@ exports.normalizeRequestArguments = async (options) => {
|
|
|
320
322
|
if ((isBody || isForm || isJson) && withoutBody.has(options.method)) {
|
|
321
323
|
throw new TypeError(`The \`${options.method}\` method cannot be used with a body`);
|
|
322
324
|
}
|
|
325
|
+
if (!options.allowGetBody && (isBody || isForm || isJson) && withoutBodyUnlessSpecified === options.method) {
|
|
326
|
+
throw new TypeError(`The \`${options.method}\` method cannot be used with a body`);
|
|
327
|
+
}
|
|
323
328
|
if ([isBody, isForm, isJson].filter(isTrue => isTrue).length > 1) {
|
|
324
329
|
throw new TypeError('The `body`, `json` and `form` options are mutually exclusive');
|
|
325
330
|
}
|
|
@@ -366,7 +371,7 @@ exports.normalizeRequestArguments = async (options) => {
|
|
|
366
371
|
// a payload body and the method semantics do not anticipate such a
|
|
367
372
|
// body.
|
|
368
373
|
if (is_1.default.undefined(headers['content-length']) && is_1.default.undefined(headers['transfer-encoding'])) {
|
|
369
|
-
if ((options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH' || options.method === 'DELETE') &&
|
|
374
|
+
if ((options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH' || options.method === 'DELETE' || (options.allowGetBody && options.method === 'GET')) &&
|
|
370
375
|
!is_1.default.undefined(uploadBodySize)) {
|
|
371
376
|
// @ts-ignore We assign if it is undefined, so this IS correct
|
|
372
377
|
headers['content-length'] = String(uploadBodySize);
|
package/dist/source/types.d.ts
CHANGED
|
@@ -145,6 +145,7 @@ export interface GotOptions extends PaginationOptions<unknown> {
|
|
|
145
145
|
};
|
|
146
146
|
maxRedirects?: number;
|
|
147
147
|
lookup?: CacheableLookup['lookup'];
|
|
148
|
+
allowGetBody?: boolean;
|
|
148
149
|
methodRewriting?: boolean;
|
|
149
150
|
}
|
|
150
151
|
export declare type Options = Merge<https.RequestOptions, Merge<GotOptions, URLOptions>>;
|
|
@@ -173,6 +174,7 @@ export interface NormalizedOptions extends Options {
|
|
|
173
174
|
followRedirect: boolean;
|
|
174
175
|
useElectronNet: boolean;
|
|
175
176
|
methodRewriting: boolean;
|
|
177
|
+
allowGetBody: boolean;
|
|
176
178
|
context: {
|
|
177
179
|
[key: string]: any;
|
|
178
180
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "got",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.6.0",
|
|
4
4
|
"description": "Human-friendly and powerful HTTP request library for Node.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/got",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"duplexer3": "^0.1.4",
|
|
51
51
|
"get-stream": "^5.0.0",
|
|
52
52
|
"lowercase-keys": "^2.0.0",
|
|
53
|
-
"mimic-response": "^2.
|
|
53
|
+
"mimic-response": "^2.1.0",
|
|
54
54
|
"p-cancelable": "^2.0.0",
|
|
55
55
|
"p-event": "^4.0.0",
|
|
56
56
|
"responselike": "^2.0.0",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"type-fest": "^0.10.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@ava/typescript": "^1.1.
|
|
61
|
+
"@ava/typescript": "^1.1.1",
|
|
62
62
|
"@sindresorhus/tsconfig": "^0.7.0",
|
|
63
63
|
"@types/duplexer3": "^0.1.0",
|
|
64
64
|
"@types/express": "^4.17.2",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"get-port": "^5.0.0",
|
|
81
81
|
"keyv": "^4.0.0",
|
|
82
82
|
"lolex": "^6.0.0",
|
|
83
|
-
"nock": "^
|
|
83
|
+
"nock": "^12.0.0",
|
|
84
84
|
"np": "^6.0.0",
|
|
85
85
|
"nyc": "^15.0.0",
|
|
86
86
|
"proxyquire": "^2.0.1",
|
package/readme.md
CHANGED
|
@@ -188,7 +188,7 @@ Type: `string | Buffer | stream.Readable` or [`form-data` instance](https://gith
|
|
|
188
188
|
|
|
189
189
|
**Note #2:** If you provide this option, `got.stream()` will be read-only.
|
|
190
190
|
|
|
191
|
-
**Note #3:** If you provide a payload with the `GET` or `HEAD` method, it will throw a `TypeError`.
|
|
191
|
+
**Note #3:** If you provide a payload with the `GET` or `HEAD` method, it will throw a `TypeError` unless the method is `GET` and the `allowGetBody` option is set to `true`.
|
|
192
192
|
|
|
193
193
|
The `content-length` header will be automatically set if `body` is a `string` / `Buffer` / `fs.createReadStream` instance / [`form-data` instance](https://github.com/form-data/form-data), and `content-length` and `transfer-encoding` are not manually set in `options.headers`.
|
|
194
194
|
|
|
@@ -410,6 +410,15 @@ Default: `true`
|
|
|
410
410
|
|
|
411
411
|
By default, redirects will use [method rewriting](https://tools.ietf.org/html/rfc7231#section-6.4). For example, when sending a POST request and receiving a `302`, it will resend the body to the new location using the same HTTP method (`POST` in this case).
|
|
412
412
|
|
|
413
|
+
###### allowGetBody
|
|
414
|
+
|
|
415
|
+
Type: `boolean`\
|
|
416
|
+
Default: `false`
|
|
417
|
+
|
|
418
|
+
**Note:** The [RFC 7321](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)**.
|
|
419
|
+
|
|
420
|
+
Set this to `true` to allow sending body for the `GET` method. 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. This option is only meant to interact with non-compliant servers when you have no other choice.
|
|
421
|
+
|
|
413
422
|
###### maxRedirects
|
|
414
423
|
|
|
415
424
|
Type: `number`\
|