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