-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
net/http: http.StripPrefix
causing incorrect Location
header and HTML page in 301 response
#69485
Comments
this is working as intended. redirects are generated by ServeMux, and if it didn't know about the prefix then it can't generate the correct 300 |
Can you give an example of when this behavior is useful? I'm struggling to see how it would be a desirable output. |
Is there a way I can tell the ServeMux to generate redirects relative to the stripped prefix, "/v1", in the above example? @seankhliao |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Go version
go version go1.23.0 linux/amd64
Output of
go env
in your module/workspace:What did you do?
When using the
http.StripPrefix
function for subrouting, the generated redirect page and Location header doesn't include the correct url. Note the "/api/" route and not "/api".curl to correct location: "/v1/api/"
curl to incorrect location: "/v1/api"
What did you see happen?
When curling the "/v1/api" route, the
Location
redirect header and generated html both redirect to "/api/" and not "/v1/api/".What did you expect to see?
When curling the "/v1/api" route, I expect the
Location
redirect header and generated html to include the "/v1" prefix, because that is where the route is.The text was updated successfully, but these errors were encountered: