-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: ServeMux forcibly cleans double forward slash in URLs even when behaving as a gateway #42244
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 fear this might be neither. RFC 2396 allows for the single slash to be a path separator. This means that a URL with two consecutive slashes implies an empty path segment. Now, while that spec is clear on the sintactic meaning of an empty path segment, it's not very clear what the semantics of that should be. That is left to the implementation. Filesystem implementations all ignore empty path segments, while other implementations differ. So this is the point about URL specifications and server implementations: the server (origin) can decide what meaning to attribute to an empty path segment. Go aligns with the Unix interpretation and ignores empty path components on server multiplexers and routers. So now we have to look into the proxy side of specs: is a hop in HTTP a receiving end for the statement above or not? In this case we are looking at gateways (aka reverse proxies). This paragraph says that requirements for a gateway are the same for origin servers on one side, and user agents for the other side and adds no restrictions. I think the best approach here would be to make a proxy rely a message as transparently as possible, so not cleaning empty path segments. So the question is not on what the spec says, but on what we decide might be better to do. That said Go's I don't think there is any change needed here as Long story short
So, before we close this I have a couple of questions for @iiiusky:
|
@empijei
The main realization is that I use |
Can you please change your last 4 lines to be: s := http.Server{
Addr: fmt.Sprintf("%s:%d", bindIP, bindPort),
Handler: http.HandlerFunc(handleRequestAndRedirect),
}
if err := s.ListenAndServe(fmt.Sprintf("%s:%d", bindIP, bindPort), nil); err != nil {
panic(err)
} and check if it works? |
It works fine instead
thinks. |
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 use golang's ReverseProxy to reverse proxy the target website. The target website has a URL address:
/tools/_ajax//forgetPwdSeting
, the request method is post, but after the proxy, golang will automatically set/tools/_ajax// ForgetPwdSeting
jumps to/tools/_ajax/forgetPwdSeting
, and there is no real access and response to the website after the jump, which is completely invalid internally, causing some functions to be unavailable after the proxy.What did you expect to see?
What did you see instead?
From the above figure and description, I found that the specific location of the intranet 301 redirection is
src/net/http/server.go:2347
The text was updated successfully, but these errors were encountered: