@ -173,13 +173,7 @@ type routeRegexp struct {
@@ -173,13 +173,7 @@ type routeRegexp struct {
// Match matches the regexp against the URL host or path.
func ( r * routeRegexp ) Match ( req * http . Request , match * RouteMatch ) bool {
if r . regexpType == regexpTypeHost {
host := getHost ( req )
if r . wildcardHostPort {
// Don't be strict on the port match
if i := strings . Index ( host , ":" ) ; i != - 1 {
host = host [ : i ]
}
}
host := getHost ( req , r . wildcardHostPort )
return r . regexp . MatchString ( host )
}
@ -287,7 +281,7 @@ type routeRegexpGroup struct {
@@ -287,7 +281,7 @@ type routeRegexpGroup struct {
func ( v routeRegexpGroup ) setMatch ( req * http . Request , m * RouteMatch , r * Route ) {
// Store host variables.
if v . host != nil {
host := getHost ( req )
host := getHost ( req , v . host . wildcardHostPort )
matches := v . host . regexp . FindStringSubmatchIndex ( host )
if len ( matches ) > 0 {
extractVars ( host , matches , v . host . varsN , m . Vars )
@ -331,11 +325,19 @@ func (v routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route) {
@@ -331,11 +325,19 @@ func (v routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route) {
// getHost tries its best to return the request host.
// 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.
func getHost ( r * http . Request ) string {
func getHost ( r * http . Request , wildcardHostPort bool ) string {
var host string
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 h ost
}
func extractVars ( input string , matches [ ] int , names [ ] string , output map [ string ] string ) {