Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new case insensitive matcher #553

Merged
merged 4 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With respect to the case-insensitive prefix matching I think iprefix is a better name.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# iprefix: case-insensitive prefix matching

#
# 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking at this again, I think this should be a case insensitive prefix match. Originally I was using EqualFold. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// todo(fs): if this turns out to be a performance issue we should cache
// todo(fs): strings.ToLower(r.Path) in r.PathLower
return strings.HasPrefix(strings.ToLower(uri), strings.ToLower(r.Path))

}
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