-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http/httputil: ReverseProxy appends trailing slash to url with empty path #50337
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
Change https://golang.org/cl/374276 mentions this issue: |
@neild per owners. |
Same here, I got 404 because of extra suffix "/" |
Is it valid per spec to have an empty url path though? I thought the resource being requested always has to be well-defined, so if you have
then you'd have path as
|
@krackers has a point. Maybe modify reverseproxy.go:singleJoiningSlash as follows (comments added):
The reverseproxy.go code is a bit strange. I've quoted it below and added
|
I was actually meaning that since it's not valid to have a GET request with empty resource being requested, we shouldn't need to handle this case in httputil itself. As I understand, the api of reverseproxy is really meant to route paths under a directory-like structure. So if you reverse proxy to Now OP's situation is that if you route to |
Hi, This is my solution: `func serveReverseProxy(target string, res http.ResponseWriter, req *http.Request) {
}` |
As @krackers says: An HTTP request URL can't contain an empty path. Should we be adding a special case to handle one, given that our existing behavior doesn't seem particularly wrong? |
Change https://go.dev/cl/595695 mentions this issue: |
Change https://go.dev/cl/658536 mentions this issue: |
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?
Attempted to serve a reverse proxy where the base URL had a RawPath and Path value of
""
, an empty string.target = "http://localhost:808/health"
req.URL.Path = ""
req.URL.RawPath = ""
What did you expect to see?
I expected the new single host reverse proxy to rout the request to
http://locahost:8080/health
What did you see instead?
It was routed to
http://localhost:8080/health/
which causes the route to throw a 404 Not Found because of the extra suffix "/"Potential Easy Fix
go/src/net/http/httputil/reverseproxy.go
Line 111 in b357b05
it this line to be
so if the base path is empty, it just returns the new path passed in instead of appending an extra slash...
The text was updated successfully, but these errors were encountered: