Propagate StrictSlash to subrouters instead of rudely turning it off

This commit is contained in:
Thomas ten Cate
2014-04-23 19:53:35 +02:00
parent 3509745ae8
commit b864f07c53
4 changed files with 24 additions and 11 deletions

View File

@@ -98,12 +98,13 @@ func newRouteRegexp(tpl string, matchHost, matchPrefix, strictSlash bool) (*rout
}
// Done!
return &routeRegexp{
template: template,
matchHost: matchHost,
regexp: reg,
reverse: reverse.String(),
varsN: varsN,
varsR: varsR,
template: template,
matchHost: matchHost,
strictSlash: strictSlash,
regexp: reg,
reverse: reverse.String(),
varsN: varsN,
varsR: varsR,
}, nil
}
@@ -114,6 +115,8 @@ type routeRegexp struct {
template string
// True for host match, false for path match.
matchHost bool
// The strictSlash value defined on the route, but disabled if PathPrefix was used.
strictSlash bool
// Expanded regexp.
regexp *regexp.Regexp
// Reverse template.
@@ -216,7 +219,7 @@ func (v *routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route)
m.Vars[v] = pathVars[k+1]
}
// Check if we should redirect.
if r.strictSlash {
if v.path.strictSlash {
p1 := strings.HasSuffix(req.URL.Path, "/")
p2 := strings.HasSuffix(v.path.template, "/")
if p1 != p2 {