@ -113,6 +113,13 @@ func newRouteRegexp(tpl string, typ regexpType, options routeRegexpOptions) (*ro
if typ != regexpTypePrefix {
if typ != regexpTypePrefix {
pattern . WriteByte ( '$' )
pattern . WriteByte ( '$' )
}
}
var wildcardHostPort bool
if typ == regexpTypeHost {
if ! strings . Contains ( pattern . String ( ) , ":" ) {
wildcardHostPort = true
}
}
reverse . WriteString ( raw )
reverse . WriteString ( raw )
if endSlash {
if endSlash {
reverse . WriteByte ( '/' )
reverse . WriteByte ( '/' )
@ -131,13 +138,14 @@ func newRouteRegexp(tpl string, typ regexpType, options routeRegexpOptions) (*ro
// Done!
// Done!
return & routeRegexp {
return & routeRegexp {
template : template ,
template : template ,
regexpType : typ ,
regexpType : typ ,
options : options ,
options : options ,
regexp : reg ,
regexp : reg ,
reverse : reverse . String ( ) ,
reverse : reverse . String ( ) ,
varsN : varsN ,
varsN : varsN ,
varsR : varsR ,
varsR : varsR ,
wildcardHostPort : wildcardHostPort ,
} , nil
} , nil
}
}
@ -158,11 +166,22 @@ type routeRegexp struct {
varsN [ ] string
varsN [ ] string
// Variable regexps (validators).
// Variable regexps (validators).
varsR [ ] * regexp . Regexp
varsR [ ] * regexp . Regexp
// Wildcard host-port (no strict port match in hostname)
wildcardHostPort bool
}
}
// 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 )
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 )
} else {
if r . regexpType == regexpTypeQuery {
if r . regexpType == regexpTypeQuery {
return r . matchQueryString ( req )
return r . matchQueryString ( req )
}
}
@ -172,8 +191,6 @@ func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool {
}
}
return r . regexp . MatchString ( path )
return r . regexp . MatchString ( path )
}
}
return r . regexp . MatchString ( getHost ( req ) )
}
}
// url builds a URL part using the given values.
// url builds a URL part using the given values.