Merge pull request #71 from Madrigal/patch-1

Rearrange code
This commit is contained in:
Kamil Kisiel
2014-09-26 08:38:14 -07:00

View File

@@ -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.
@@ -262,13 +263,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
}
return r.URL.Host
host := r.Host
// Slice off any port information.
if i := strings.Index(host, ":"); i != -1 {
host = host[:i]
}
return host
}