Got: Got throws an error instead of redirecting for 303, 307 or 308

Created on 1 Apr 2017  ·  9Comments  ·  Source: sindresorhus/got

{ HTTPError: Response code 308 (Permanent Redirect)
    at EventEmitter.ee.on.res (/home/user/Desktop/REPOS/transfer-sh/node_modules/got/index.js:182:24)
    at emitOne (events.js:96:13)
    at EventEmitter.emit (events.js:188:7)
    at Immediate.setImmediate (/home/user/Desktop/REPOS/transfer-sh/node_modules/got/index.js:61:8)
    at tryOnImmediate (timers.js:543:15)
    at processImmediate [as _immediateCallback] (timers.js:523:5)
  message: 'Response code 308 (Permanent Redirect)',
  host: 'transfer.sh',
  hostname: 'transfer.sh',
  method: 'PUT',
  path: '/README.md',
  statusCode: 308,
  statusMessage: 'Permanent Redirect' }

Redirect not followed?

enhancement ✭ help wanted ✭

All 9 comments

No. I'm not an expert on HTTP, but I just did a lot of HTTP/1.1 RFC reading (fascinating!). Let me try and help out by adding my view and /cc someone who I sense is an expert on this.

/cc @floatdrop

RFC 7231, section 6.4.2

If the origin server will not make the requested PUT state change to
the target resource and instead wishes to have it applied to a
different resource, such as when the resource has been moved to a
different URI, then the origin server MUST send an appropriate 3xx
(Redirection) response; the user agent MAY then make its own decision
regarding whether or not to redirect the request.

In other words, it's entirely our choice. That said I'm in favor redirecting. The 303, 307 and 308 status codes were clearly meant to finally make redirecting unambiguous. What to do is very clear.
Currently, we only redirect GET and HEAD methods on all of the redirect status codes.
I propose we:

  1. redirect POST on 303, and continue with GET.
  2. redirect any on 307 or 308 and continue with the same method.

+1

@ninox92 you can use the emoji reactions in the top right of the comment boxes to avoid adding unnecessary activity 😉. Usually, people use the adequately named '+1' to indicate they share an opinion.

@AlexTes I agree with your assessment. @floatdrop ?


For reference:

303

If a server responds to a POST or other non-idempotent request with a 303 See Other response and a value for the location header, the client is expected to obtain the resource mentioned in the location header using the GET method; - https://en.m.wikipedia.org/wiki/HTTP_303

@sindresorhus @AlexTes we should implement it, if rfc says so. 👍

There were an idea to switch to follow-redirects module, but it does not support 303 and 308 codes too.

There were an idea to switch to follow-redirects module, but it does not support 303 and 308 codes too.

I don't really see any upsides of doing that then. Only potential subtle regressions.

we should implement it, if rfc says so. 👍

Cool. Pull request welcome then :)

Can we maybe change the title to: 'Got throws an error instead of redirecting for 303, 307 or 308'?

Done

Was this page helpful?
0 / 5 - 0 ratings

Related issues

khizarsonu picture khizarsonu  ·  3Comments

f-mer picture f-mer  ·  4Comments

lukehorvat picture lukehorvat  ·  3Comments

alvis picture alvis  ·  3Comments

alanzhaonys picture alanzhaonys  ·  4Comments