Skip to content

Commit

Permalink
Updates per PR comments. Also, modified noCaseMatcher to be a prefix …
Browse files Browse the repository at this point in the history
…match
  • Loading branch information
herbrandson committed Sep 20, 2018
1 parent 9e1e189 commit b77f9d9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func load(cmdline, environ, envprefix []string, props *properties.Properties) (c
return nil, fmt.Errorf("invalid proxy.strategy: %s", cfg.Proxy.Strategy)
}

if cfg.Proxy.Matcher != "prefix" && cfg.Proxy.Matcher != "glob" && cfg.Proxy.Matcher != "noCase" {
if cfg.Proxy.Matcher != "prefix" && cfg.Proxy.Matcher != "glob" && cfg.Proxy.Matcher != "nocase" {
return nil, fmt.Errorf("invalid proxy.matcher: %s", cfg.Proxy.Matcher)
}

Expand Down
7 changes: 7 additions & 0 deletions config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ func TestLoad(t *testing.T) {
return cfg
},
},
{
args: []string{"-proxy.matcher", "nocase"},
cfg: func(cfg *Config) *Config {
cfg.Proxy.Matcher = "nocase"
return cfg
},
},
{
args: []string{"-proxy.noroutestatus", "555"},
cfg: func(cfg *Config) *Config {
Expand Down
6 changes: 4 additions & 2 deletions docs/content/ref/proxy.matcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ title: "proxy.matcher"
* `prefix`: prefix matching
* `glob`: glob matching

When `prefix` matching is enabled then the route path must be a
prefix of the request URI, e.g. `/foo` matches `/foo`, `/foot` but
When `prefix` matching is enabled then the route path must be a
prefix of the request URI, e.g. `/foo` matches `/foo`, `/foot` but
not `/fo`.

When `glob` matching is enabled the route is evaluated according to
Expand All @@ -19,6 +19,8 @@ function.
For example, `/foo*` matches `/foo`, `/fool` and `/fools`. Also, `/foo/*/bar`
matches `/foo/x/bar`.

`nocase` matching is similar to `prefix`, except it uses a case insensitive comparison

The default is

proxy.matcher = prefix
1 change: 1 addition & 0 deletions fabio.properties
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
#
# prefix: prefix matching
# glob: glob matching
# nocase: matches using a case insensitive test
#
# The default is
#
Expand Down
6 changes: 4 additions & 2 deletions route/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type matcher func(uri string, r *Route) bool
var Matcher = map[string]matcher{
"prefix": prefixMatcher,
"glob": globMatcher,
"noCase": noCaseMatcher,
"nocase": noCaseMatcher,
}

// prefixMatcher matches path to the routes' path.
Expand All @@ -27,5 +27,7 @@ func globMatcher(uri string, r *Route) bool {

// noCase matches path to the routes' path ignoring case
func noCaseMatcher(uri string, r *Route) bool {
return strings.EqualFold(uri, r.Path)
lowerURI := strings.ToLower(uri)
lowerPath := strings.ToLower(r.Path)
return strings.HasPrefix(lowerURI, lowerPath)
}
4 changes: 2 additions & 2 deletions route/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func TestNoCaseMatcher(t *testing.T) {
matches bool
route *Route
}{
{uri: "/fool", matches: false, route: &Route{Path: "/foo"}},
{uri: "/foo", matches: false, route: &Route{Path: "/fool"}},
{uri: "/foo", matches: true, route: &Route{Path: "/foo"}},
{uri: "/Foo", matches: true, route: &Route{Path: "/foo"}},
{uri: "/Fool", matches: true, route: &Route{Path: "/foo"}},
{uri: "/foo", matches: true, route: &Route{Path: "/Foo"}},
}

Expand Down

0 comments on commit b77f9d9

Please sign in to comment.