-
-
Notifications
You must be signed in to change notification settings - Fork 941
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
Invert the methodRewriting
option logic
#1307
Comments
That spec is outdated, take a look at RFC7231 section 6.4 |
Yeah, I agree that's a newer version of the spec, but it's saying the same thing as the spec I linked. In fact it even clarifies on what I was saying. First of all, in the main part of the redirection section 6.4 it says:
Where a 'safe' method is defined:
In other words, a POST is generally not considered 'safe' and should not be replayed on redirection. Additionally in the notes for the redirection section, it goes on to clarify exactly what I pointed out with this issue:
So the newer RFC is explicitly pointing out that changing the method to a GET on the redirection URL after a 301 or 302 from a POST is the officially recognized and conformant behavior. |
@Giotino Please also note that term
I agree that this should be modified. The meaning of
The default should be kept as Additionally, given #1271 it is clear that this is not behavior expected by people using |
If we were to rename this or change the behavior, we would do so in Got 12. Honestly I don't know what to do about this. We have provided an example in the docs. @sindresorhus Have any ideas? |
methodRewriting
valid?
methodRewriting
valid?methodRewriting
option valid?
I agree with @proton-ab's proposal. We should get this fixed in Got 12. |
methodRewriting
option valid?methodRewriting
option logic
It's worth noting that you do not want to rewrite unsafe methods by default for all 3XX responses. Specifically, 307 and 308 were explicitly created to indicate that the client should repeat the original (potentially unsafe) method on the new location. You'll probably only want to rewrite 'unsafe' methods by default for 301, 302, and 303, as that most closely follows the HTTP spec as well as conventions set by most other HTTP clients and web browsers. |
Fixed in 51d88a0 |
Describe the bug
According to the HTTP spec in RFC2616, HTTP clients should NOT redirect on 3XX response codes UNLESS the original request was a GET or a HEAD.
Got's default behavior causes it to repeat the original request (even if it's something like a POST) to the redirect URL, breaking very common webserver upload patterns.
Actual behavior
Common webserver behavior is to accept a POST to create some sort of resource, then reply with a 302 to point the user to the newly creating resource.
Got's default redirection behavior is to simply perform the same exact request again on some redirect code, regardless of the initial request method. So a POST request with the same body was then performed to the new URL from the location header of the redirect, which almost always will cause an error, as the redirected location generally will not accept a POST request, and certainly not expecting the same body.
Expected behavior
HTTP spec indicates that you SHOULD NOT automatically redirect any request that is not originally a GET or a HEAD request.
As for this specific scenario, it's worth noting that every single web browser, and a vast majority of HTTP clients treat a 302 after a POST as a redirection to then perform a GET on the 302, even though the original request was a POST.
At the very least by default got should not repeat requests to a redirected location on 3XX if the original request was not a GET or a HEAD, to stay compliant with the http spec by default.
Code to reproduce
Checklist
The text was updated successfully, but these errors were encountered: