-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: redirect with 308 rather than 301 #60769
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
Comments
I don't think the net/http server does that |
Per https://pkg.go.dev/net/http#Client.Do:
That is also consistent with the behavior described in RFC 9110; see in particular the note at https://www.rfc-editor.org/rfc/rfc9110.html#section-15.4-3.1. Where this comes into play on the server side is with path cleaning in But that makes me wonder: should (attn @neild) |
Changing |
I guess the caveat with status 308 is (per https://www.rfc-editor.org/rfc/rfc7538#section-4) that that status code has only been defined since June 2014, so some very old HTTP clients still might not understand it. Still, though, I think with an appropriate GODEBUG setting to revert to 301, 308 seems like a better semantic fit, and 9 years seems like long enough for clients to have built out support... |
Sounds like this is a reasonable net/http change, so taking it out of the proposal process. Please comment if you disagree. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I implemented an HTTP proxy server in Go using the net/http package. The server is supposed to handle and forward incoming requests without modifying them. The proxy server encountered a specific scenario where incoming HTTP requests have a double slash ("//") at the beginning of their path, for instance, //PAM-OAuth/oauth2/token.
What did you expect to see?
I expected the Go net/http library to forward the incoming requests as is, preserving their original form including the HTTP method, the path with the double slash and all request parameters.
What did you see instead?
What I observed was the HTTP request's method was inadvertently changed from POST to GET during the proxying process, and the request path was altered from //PAM-OAuth/oauth2/token to /PAM-OAuth/oauth2/token (removing the double slash). Moreover, the request parameters were lost during this process, leading to a failed request when it reached the final destination server.
I understand that the net/http package may be trying to sanitize the request path by removing the double slash. However, in the context of a proxy server, this automatic alteration of the request details leads to unintended consequences and erroneous behavior.
To resolve this issue, I propose adding an option to disable this automatic sanitization or clean-up in the net/http package, especially in proxy server scenarios. This would ensure that the incoming HTTP requests are faithfully forwarded as they are, without any alterations to the request method, path, or parameters.
Please consider this proposal as it would significantly improve the usability and robustness of the Go net/http package in handling complex real-world scenarios such as proxy server implementations.
I look forward to your feedback and am happy to provide any further details or clarifications as needed.
The text was updated successfully, but these errors were encountered: