Browse Source

Merge pull request #71 from Madrigal/patch-1

Rearrange code
pull/53/merge
Kamil Kisiel 11 years ago
parent
commit
e444e69cbd
  1. 14
      regexp.go

14
regexp.go

@ -35,12 +35,13 @@ func newRouteRegexp(tpl string, matchHost, matchPrefix, matchQuery, strictSlash
defaultPattern := "[^/]+" defaultPattern := "[^/]+"
if matchQuery { if matchQuery {
defaultPattern = "[^?&]+" defaultPattern = "[^?&]+"
matchPrefix, strictSlash = true, false matchPrefix = true
} else if matchHost { } else if matchHost {
defaultPattern = "[^.]+" defaultPattern = "[^.]+"
matchPrefix, strictSlash = false, false matchPrefix = false
} }
if matchPrefix { // Only match strict slash if not matching
if matchPrefix || matchHost || matchQuery {
strictSlash = false strictSlash = false
} }
// Set a flag for strictSlash. // 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. // getHost tries its best to return the request host.
func getHost(r *http.Request) string { func getHost(r *http.Request) string {
if !r.URL.IsAbs() { if r.URL.IsAbs() {
return r.URL.Host
}
host := r.Host host := r.Host
// Slice off any port information. // Slice off any port information.
if i := strings.Index(host, ":"); i != -1 { if i := strings.Index(host, ":"); i != -1 {
host = host[:i] host = host[:i]
} }
return host return host
}
return r.URL.Host
} }

Loading…
Cancel
Save