|
|
|
@ -151,10 +151,11 @@ func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool { |
|
|
|
if !r.matchHost { |
|
|
|
if !r.matchHost { |
|
|
|
if r.matchQuery { |
|
|
|
if r.matchQuery { |
|
|
|
return r.matchQueryString(req) |
|
|
|
return r.matchQueryString(req) |
|
|
|
} else { |
|
|
|
|
|
|
|
return r.regexp.MatchString(req.URL.Path) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return r.regexp.MatchString(req.URL.Path) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return r.regexp.MatchString(getHost(req)) |
|
|
|
return r.regexp.MatchString(getHost(req)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -184,10 +185,10 @@ func (r *routeRegexp) url(values map[string]string) (string, error) { |
|
|
|
return rv, nil |
|
|
|
return rv, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// getUrlQuery returns a single query parameter from a request URL.
|
|
|
|
// getURLQuery returns a single query parameter from a request URL.
|
|
|
|
// For a URL with foo=bar&baz=ding, we return only the relevant key
|
|
|
|
// For a URL with foo=bar&baz=ding, we return only the relevant key
|
|
|
|
// value pair for the routeRegexp.
|
|
|
|
// value pair for the routeRegexp.
|
|
|
|
func (r *routeRegexp) getUrlQuery(req *http.Request) string { |
|
|
|
func (r *routeRegexp) getURLQuery(req *http.Request) string { |
|
|
|
if !r.matchQuery { |
|
|
|
if !r.matchQuery { |
|
|
|
return "" |
|
|
|
return "" |
|
|
|
} |
|
|
|
} |
|
|
|
@ -201,14 +202,14 @@ func (r *routeRegexp) getUrlQuery(req *http.Request) string { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (r *routeRegexp) matchQueryString(req *http.Request) bool { |
|
|
|
func (r *routeRegexp) matchQueryString(req *http.Request) bool { |
|
|
|
return r.regexp.MatchString(r.getUrlQuery(req)) |
|
|
|
return r.regexp.MatchString(r.getURLQuery(req)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// braceIndices returns the first level curly brace indices from a string.
|
|
|
|
// braceIndices returns the first level curly brace indices from a string.
|
|
|
|
// It returns an error in case of unbalanced braces.
|
|
|
|
// It returns an error in case of unbalanced braces.
|
|
|
|
func braceIndices(s string) ([]int, error) { |
|
|
|
func braceIndices(s string) ([]int, error) { |
|
|
|
var level, idx int |
|
|
|
var level, idx int |
|
|
|
idxs := make([]int, 0) |
|
|
|
var idxs []int |
|
|
|
for i := 0; i < len(s); i++ { |
|
|
|
for i := 0; i < len(s); i++ { |
|
|
|
switch s[i] { |
|
|
|
switch s[i] { |
|
|
|
case '{': |
|
|
|
case '{': |
|
|
|
@ -278,10 +279,10 @@ func (v *routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route) |
|
|
|
} |
|
|
|
} |
|
|
|
// Store query string variables.
|
|
|
|
// Store query string variables.
|
|
|
|
for _, q := range v.queries { |
|
|
|
for _, q := range v.queries { |
|
|
|
queryUrl := q.getUrlQuery(req) |
|
|
|
queryURL := q.getURLQuery(req) |
|
|
|
matches := q.regexp.FindStringSubmatchIndex(queryUrl) |
|
|
|
matches := q.regexp.FindStringSubmatchIndex(queryURL) |
|
|
|
if len(matches) > 0 { |
|
|
|
if len(matches) > 0 { |
|
|
|
extractVars(queryUrl, matches, q.varsN, m.Vars) |
|
|
|
extractVars(queryURL, matches, q.varsN, m.Vars) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|