From 8df3a80fb8cd2b280d3b0b7d809ad80c1d0be236 Mon Sep 17 00:00:00 2001 From: Felipe Madrigal Date: Fri, 26 Sep 2014 00:20:12 -0500 Subject: [PATCH 1/2] Rearrange getHost function --- regexp.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/regexp.go b/regexp.go index ef1db8f..35c8177 100644 --- a/regexp.go +++ b/regexp.go @@ -262,13 +262,14 @@ func (v *routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route) // getHost tries its best to return the request host. func getHost(r *http.Request) string { - if !r.URL.IsAbs() { - host := r.Host - // Slice off any port information. - if i := strings.Index(host, ":"); i != -1 { - host = host[:i] - } - return host + if r.URL.IsAbs() { + return r.URL.Host + } + host := r.Host + // Slice off any port information. + if i := strings.Index(host, ":"); i != -1 { + host = host[:i] } - return r.URL.Host + return host + } From d7e46398189abd89d18d874e3c53b42d492002b8 Mon Sep 17 00:00:00 2001 From: Felipe Madrigal Date: Fri, 26 Sep 2014 00:20:46 -0500 Subject: [PATCH 2/2] Rearrange rules for matching strict slash --- regexp.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/regexp.go b/regexp.go index 35c8177..a630548 100644 --- a/regexp.go +++ b/regexp.go @@ -35,12 +35,13 @@ func newRouteRegexp(tpl string, matchHost, matchPrefix, matchQuery, strictSlash defaultPattern := "[^/]+" if matchQuery { defaultPattern = "[^?&]+" - matchPrefix, strictSlash = true, false + matchPrefix = true } else if matchHost { defaultPattern = "[^.]+" - matchPrefix, strictSlash = false, false + matchPrefix = false } - if matchPrefix { + // Only match strict slash if not matching + if matchPrefix || matchHost || matchQuery { strictSlash = false } // Set a flag for strictSlash.