-
-
Notifications
You must be signed in to change notification settings - Fork 957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redirect on 307, 308, 303 #307
Redirect on 307, 308, 303 #307
Conversation
Fails on node4, which shouldn't be a blocker for changes to 7.0.0 release. |
index.js
Outdated
@@ -21,6 +20,9 @@ const isPlainObj = require('is-plain-obj'); | |||
const PCancelable = require('p-cancelable'); | |||
const pkg = require('./package'); | |||
|
|||
const getMethodRedirectCodes = [300, 301, 302, 303, 304, 305, 307, 308]; | |||
const allMethodRedirectCodes = [300, 303, 307, 308]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a good use for Set()
. You could then use .has()
instead of .includes()
on line 50.
index.js
Outdated
const redirectGet = followRedirect && getMethodRedirectCodes.includes(statusCode); | ||
const redirectAll = followRedirect && allMethodRedirectCodes.includes(statusCode); | ||
|
||
if (redirectAll || (redirectGet && ['GET', 'HEAD'].includes(opts.method))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still support Node.js 4. Just do .includes(opts.method)
=> .indexOf(opts.method) !== -1
From what I could tell from https://en.m.wikipedia.org/wiki/HTTP_303 it should use the original method, unless it's |
From RFC 7231:
My reading:
Based on this, maybe we should have some kind of error response specific to receiving a 303 in response to a GET? Since clients may need to make a decision about how to proceed. While we're on the topic, according to the spec, we should probably do something similar in response to a 300:
|
I would always use GET. People can create an issue if there is a need for a GET or HEAD option. EDIT: sindresorhus if I remember correctly it's for any method. One can imagine deleting a resource that's maybe a child to a parent and thus the server redirects to the parent resource for the result. |
Actually not sure what I would update in the README, except maybe the surprising behavior of changing from POST/PUT/DELETE to GET on a 303 response? Seems like a case for a changelog entry if one existed. |
I think that would be enough. Can you add that to the readme?
It does: https://github.com/sindresorhus/got/releases
I guess we could redirect then too if a |
@sindresorhus updated README. 300 redirects are already followed; my question was whether, since the spec describes a 300 response as containing multiple choices, we should throw an error in this case so the consumer has a chance to decide which resource to request next. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Regarding multiple choices in redirects – I never met this in real life. I would take |
Fixes #291.
Open questions:
TODO: