diff --git a/config/load.go b/config/load.go index 3261ccfd9..aa6cfda26 100644 --- a/config/load.go +++ b/config/load.go @@ -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) } diff --git a/config/load_test.go b/config/load_test.go index fc17f186d..8f3150548 100644 --- a/config/load_test.go +++ b/config/load_test.go @@ -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 { diff --git a/docs/content/ref/proxy.matcher.md b/docs/content/ref/proxy.matcher.md index f029f29ef..38af329e7 100644 --- a/docs/content/ref/proxy.matcher.md +++ b/docs/content/ref/proxy.matcher.md @@ -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 @@ -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 diff --git a/fabio.properties b/fabio.properties index 703027d3d..4887267d8 100644 --- a/fabio.properties +++ b/fabio.properties @@ -297,6 +297,7 @@ # # prefix: prefix matching # glob: glob matching +# nocase: matches using a case insensitive test # # The default is # diff --git a/route/matcher.go b/route/matcher.go index b0449ff0f..dd951ce49 100644 --- a/route/matcher.go +++ b/route/matcher.go @@ -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. @@ -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) } diff --git a/route/matcher_test.go b/route/matcher_test.go index 2972acbbb..89284bbd9 100644 --- a/route/matcher_test.go +++ b/route/matcher_test.go @@ -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"}}, }