Description
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).