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
Improve methodRewriting
option
#2136
Comments
Got is not a browser, but a modern HTTP client so this is very unlikely. |
I am very aware that got is not a browser 😄 However, as it needs to deal with all sort of HTTP servers - modern and old-fashioned, and the servers might not implement the full HTTP/1.1 standard for compatibility reasons, I still think this is a worthwhile extension of a "disabled-by-default" option. E.g., there's also the
and
So, I think the same reasoning can be applied to add an option as I have described it (as indeed, I do have no other choice than to work with such non-compliant servers) |
Given that you can work around this (the code you provided), is making this even more unlikely to be implemented in Got. |
Many thanks for your responses @szmarczak - I do see and respect your point of view. As I think the basic point of our discussion should be RFC compliance, I did some further research, as the topic started to raise my curiosity. TL;DR: Both approaches, i.e., changing HTTP methods after 301 and 302, or leaving them as-is, are compliant with RFC7231 "Hypertext Transfer Protocol (HTTP/1.1)". As the fully-fledged HTTP client I will gladly volunteer to implement this feature and submit a PR including doc and tests in case this has any chance of being accepted. In case this feature request is not going to be accepted, I would suggest at least adding a short notice in the documentation including the hook-based workaround. Long Story RFC7231 Section 6.4 actually has a lengthy note about this topic (accentuation added by myself):
Also, interestingly, it seems that Further widely-used non-browser HTTP clients like the |
I'm not against an option, but we need more feedback. /cc @sindresorhus |
I'm ok with adding an option for it. |
Ok, many thanks for your updates! I will submit a PR soonish 😃 |
@sindresorhus @szmarczak : Before I start the implementation, I'd appreciate your feedback on my basic idea to implement this (after some further thoughts): I do propose to add an option named The default value for this option would be I think this would be a flexible way of giving the user control when he needs it while preserving the basic decision to follow the intention of the HTTP/1.1 spec by default (which, indeed, would prefer to preserve the request method on 301 and 302). Would you agree with this design? Any better proposals for the option's name than |
Sounds good 👍 |
Ok, bummer... While implementing, I found that there actually is already an option kind of doing what I need, i.e., the So, this actually solves my initial problem. However, I'd propose two improvements:
|
PR welcome |
methodRewriting
option
See PR #2145 |
What problem are you trying to solve?
The documentation correctly states:
However, Section 6.4.3 of the same RFC also states:
And indeed, I observe that even modern browsers like Chrome and/or Firefox do actually interpret a 302 in response to a POST Request as if it was a 303. I furthermore observe that there are still quite some servers around (including some I have to work with at my workplace) that do send 302 responses even though they should actually send 303 - be it because they need to handle legacy (i.e., pre-HTTP/1.1) clients which do not understand a 303 status code, or simply because they can count on the Browsers to do the right thing.
Describe the feature
For working with servers which do behave as described above (i.e., which send 302 responses when they actually should send a 303), it would be great to have an option which enables "legacy-handling" of 302 responses, i.e., which also changes the request method to
GET
and clears all request body contents when receiving a 302 response status code.Currently, I always need to do a workaround like this:
Checklist
The text was updated successfully, but these errors were encountered: