summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-11-28 21:11:45 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2019-11-28 21:11:45 -0700
commit14d3fd7d0307e69c3c8995c42052b9103d1e2299 (patch)
treebd6ac36a7034cfa27226151c9e275b60ab94f3f0 /modules
parent512b004332ebf6dfa3fd14269de3cb0031233e34 (diff)
http: path matcher supports exact matching with = prefix
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/matchers.go20
-rw-r--r--modules/caddyhttp/matchers_test.go15
2 files changed, 32 insertions, 3 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index 508f78f..5ea606d3 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -166,16 +166,30 @@ func (m MatchPath) Provision(_ caddy.Context) error {
func (m MatchPath) Match(r *http.Request) bool {
lowerPath := strings.ToLower(r.URL.Path)
for _, matchPath := range m {
- // as a special case, if the first character is a
- // wildcard, treat it as a quick suffix match
+ // special case: first character is equals sign,
+ // treat it as an exact match
+ if strings.HasPrefix(matchPath, "=") {
+ if lowerPath == matchPath[1:] {
+ return true
+ }
+ continue
+ }
+
+ // special case: first character is a wildcard,
+ // treat it as a fast suffix match
if strings.HasPrefix(matchPath, "*") {
- return strings.HasSuffix(lowerPath, matchPath[1:])
+ if strings.HasSuffix(lowerPath, matchPath[1:]) {
+ return true
+ }
+ continue
}
+
// can ignore error here because we can't handle it anyway
matches, _ := filepath.Match(matchPath, lowerPath)
if matches {
return true
}
+
if strings.HasPrefix(lowerPath, matchPath) {
return true
}
diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go
index 4569425..321d3ce 100644
--- a/modules/caddyhttp/matchers_test.go
+++ b/modules/caddyhttp/matchers_test.go
@@ -213,6 +213,21 @@ func TestPathMatcher(t *testing.T) {
expect: false,
},
{
+ match: MatchPath{"=/foo"},
+ input: "/foo",
+ expect: true,
+ },
+ {
+ match: MatchPath{"=/foo"},
+ input: "/foo/bar",
+ expect: false,
+ },
+ {
+ match: MatchPath{"=/foo"},
+ input: "/FOO",
+ expect: true,
+ },
+ {
match: MatchPath{"/foo"},
input: "/FOO",
expect: true,