Skip to content
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: ServeMux unexpectedly redirecting to add trailing slash #11757

Closed
jehiah opened this issue Jul 17, 2015 · 5 comments

Comments

Projects
None yet
5 participants
@jehiah
Copy link

commented Jul 17, 2015

http.ServeMux unexpectedly redirects to add a trailing slash if there is a route that matches with a trailing slash.

Given the following ServeMux, I expect that a request for /a would match the path rooted as /.

http.HandleFunc("/", ...)
http.HandleFunc("/a/", ...)

Instead, a 301 redirect is returned redirecting to /a/ (see http://play.golang.org/p/65Skm2I5hq).

The docs describe redirects as happening in path sanitization cases (ie: requests with . or .. elements), but no mention of transparently adding slashes. The docs also describe the match as a "rooted subtree" so it's also unexpected that a pattern for /a/ would affect requests that don't have that prefix (ie: w/o the trailing slash).

In researching if this situation was reported before, I found a mailing list from 2010 implying this was expected as well as a code comment. If that is still the case, then i think the docs should reflect that. (though i personally consider this a bug, i could understand that for some this could be a feature).

@jehiah jehiah changed the title http.ServeMux: unexpectedly redirecting to add trailing slash net/http: ServeMux unexpectedly redirecting to add trailing slash Jul 17, 2015

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Jul 17, 2015

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 17, 2015

@jehiah

This comment has been minimized.

Copy link
Author

commented Jul 18, 2015

For context I've looked at how this is handled by other http routers. It's mixed as to how default implementations behave, but generally is documented clearly with a configurable.

@gopherbot

This comment has been minimized.

Copy link

commented Dec 17, 2015

CL https://golang.org/cl/17955 mentions this issue.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 17, 2015

@jehiah FWIW, the configurable here is that you register the non-slash form too and tell the ServeMux what should handle it.

@jehiah

This comment has been minimized.

Copy link
Author

commented Dec 17, 2015

Thanks for the doc clarifications! much appreciated @rsc

@rsc rsc closed this in aaa0bc1 Dec 17, 2015

@golang golang locked and limited conversation to collaborators Dec 29, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.