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
Closed

net/http: ServeMux unexpectedly redirecting to add trailing slash #11757

jehiah opened this issue Jul 17, 2015 · 5 comments

Comments

@jehiah
Copy link

jehiah 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
Copy link
Contributor

CC @bradfitz

@jehiah
Copy link
Author

jehiah 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
Copy link

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

@rsc
Copy link
Contributor

rsc 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
Copy link
Author

jehiah commented Dec 17, 2015

Thanks for the doc clarifications! much appreciated @rsc

@rsc rsc closed this as completed in aaa0bc1 Dec 17, 2015
@golang golang locked and limited conversation to collaborators Dec 29, 2016
@rsc rsc removed their assignment Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants