Skip to content

Commit 51d88a0

Browse files
committed
Invert the methodRewriting option
1 parent c1b6929 commit 51d88a0

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

readme.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,9 @@ Note that if a `303` is sent by the server in response to any request type (`POS
596596
Type: `boolean`\
597597
Default: `true`
598598

599-
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).
599+
Specifies if the redirects should be [rewritten as `GET`](https://tools.ietf.org/html/rfc7231#section-6.4).
600+
601+
If `false`, 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).
600602

601603
###### allowGetBody
602604

source/core/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,11 @@ interface PlainOptions extends URLOptions {
643643
headers?: Headers;
644644

645645
/**
646-
By default, redirects will use [method rewriting](https://tools.ietf.org/html/rfc7231#section-6.4).
647-
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).
646+
Specifies if the redirects should be [rewritten as `GET`](https://tools.ietf.org/html/rfc7231#section-6.4).
648647
649-
@default true
648+
If `false`, 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).
649+
650+
@default false
650651
*/
651652
methodRewriting?: boolean;
652653

@@ -2051,7 +2052,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
20512052
}
20522053

20532054
const shouldBeGet = statusCode === 303 && options.method !== 'GET' && options.method !== 'HEAD';
2054-
if (shouldBeGet || !options.methodRewriting) {
2055+
if (shouldBeGet || options.methodRewriting) {
20552056
// Server responded with "see other", indicating that the resource exists at another location,
20562057
// and the client should request it from that location via GET or HEAD.
20572058
options.method = 'GET';

source/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const defaults: InstanceDefaults = {
6262
resolveBodyOnly: false,
6363
maxRedirects: 10,
6464
prefixUrl: '',
65-
methodRewriting: true,
65+
methodRewriting: false,
6666
ignoreInvalidCookies: false,
6767
context: {},
6868
// TODO: Set this to `true` for Got 13.

test/redirects.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ test('body is passed on POST redirect', withServer, async (t, server, got) => {
397397
t.is(body, 'foobar');
398398
});
399399

400-
test('method rewriting can be turned off', withServer, async (t, server, got) => {
400+
test('method rewriting', withServer, async (t, server, got) => {
401401
server.post('/redirect', (_request, response) => {
402402
response.writeHead(302, {
403403
location: '/'
@@ -411,7 +411,7 @@ test('method rewriting can be turned off', withServer, async (t, server, got) =>
411411

412412
const {body} = await got.post('redirect', {
413413
body: 'foobar',
414-
methodRewriting: false,
414+
methodRewriting: true,
415415
hooks: {
416416
beforeRedirect: [
417417
options => {

0 commit comments

Comments
 (0)