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" {
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
6 changes: 6 additions & 0 deletions route/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type matcher func(uri string, r *Route) bool
var Matcher = map[string]matcher{
"prefix": prefixMatcher,
"glob": globMatcher,
"noCase": noCaseMatcher,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like this might be a terrible name, but it's the best I could come up with this evening. I'm open to suggestions

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe nocase

}

// prefixMatcher matches path to the routes' path.
Expand All @@ -23,3 +24,8 @@ func prefixMatcher(uri string, r *Route) bool {
func globMatcher(uri string, r *Route) bool {
return r.Glob.Match(uri)
}

// noCase matches path to the routes' path ignoring case
func noCaseMatcher(uri string, r *Route) bool {
return strings.EqualFold(uri, r.Path)
}
21 changes: 21 additions & 0 deletions route/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,24 @@ func TestGlobMatcher(t *testing.T) {
})
}
}

func TestNoCaseMatcher(t *testing.T) {
tests := []struct {
uri string
matches bool
route *Route
}{
{uri: "/fool", matches: false, route: &Route{Path: "/foo"}},
{uri: "/foo", matches: true, route: &Route{Path: "/foo"}},
{uri: "/Foo", matches: true, route: &Route{Path: "/foo"}},
{uri: "/foo", matches: true, route: &Route{Path: "/Foo"}},
}

for _, tt := range tests {
t.Run(tt.uri, func(t *testing.T) {
if got, want := noCaseMatcher(tt.uri, tt.route), tt.matches; got != want {
t.Fatalf("got %v want %v", got, want)
}
})
}
}