|
|
|
@ -173,13 +173,7 @@ type routeRegexp struct { |
|
|
|
// Match matches the regexp against the URL host or path.
|
|
|
|
// Match matches the regexp against the URL host or path.
|
|
|
|
func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool { |
|
|
|
func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool { |
|
|
|
if r.regexpType == regexpTypeHost { |
|
|
|
if r.regexpType == regexpTypeHost { |
|
|
|
host := getHost(req) |
|
|
|
host := getHost(req, r.wildcardHostPort) |
|
|
|
if r.wildcardHostPort { |
|
|
|
|
|
|
|
// Don't be strict on the port match
|
|
|
|
|
|
|
|
if i := strings.Index(host, ":"); i != -1 { |
|
|
|
|
|
|
|
host = host[:i] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return r.regexp.MatchString(host) |
|
|
|
return r.regexp.MatchString(host) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -287,7 +281,7 @@ type routeRegexpGroup struct { |
|
|
|
func (v routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route) { |
|
|
|
func (v routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route) { |
|
|
|
// Store host variables.
|
|
|
|
// Store host variables.
|
|
|
|
if v.host != nil { |
|
|
|
if v.host != nil { |
|
|
|
host := getHost(req) |
|
|
|
host := getHost(req, v.host.wildcardHostPort) |
|
|
|
matches := v.host.regexp.FindStringSubmatchIndex(host) |
|
|
|
matches := v.host.regexp.FindStringSubmatchIndex(host) |
|
|
|
if len(matches) > 0 { |
|
|
|
if len(matches) > 0 { |
|
|
|
extractVars(host, matches, v.host.varsN, m.Vars) |
|
|
|
extractVars(host, matches, v.host.varsN, m.Vars) |
|
|
|
@ -331,11 +325,19 @@ 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.
|
|
|
|
// According to section 14.23 of RFC 2616 the Host header
|
|
|
|
// According to section 14.23 of RFC 2616 the Host header
|
|
|
|
// can include the port number if the default value of 80 is not used.
|
|
|
|
// can include the port number if the default value of 80 is not used.
|
|
|
|
func getHost(r *http.Request) string { |
|
|
|
func getHost(r *http.Request, wildcardHostPort bool) string { |
|
|
|
|
|
|
|
var host string |
|
|
|
if r.URL.IsAbs() { |
|
|
|
if r.URL.IsAbs() { |
|
|
|
return r.URL.Host |
|
|
|
host = r.URL.Host |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
host = r.Host |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if wildcardHostPort { |
|
|
|
|
|
|
|
if i := strings.Index(host, ":"); i != -1 { |
|
|
|
|
|
|
|
host = host[:i] |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return r.Host |
|
|
|
return host |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func extractVars(input string, matches []int, names []string, output map[string]string) { |
|
|
|
func extractVars(input string, matches []int, names []string, output map[string]string) { |
|
|
|
|