summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/matchers.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-03-16 16:08:33 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-03-16 16:08:33 -0600
commitb62f8e058270aff37621b69a9768235a01e8bd34 (patch)
treed51ae6c3c67134fd55852212ca024a0815a64853 /modules/caddyhttp/matchers.go
parentae86f6dd91b471067082a48d14d94b868e07474c (diff)
caddyhttp: Support path matcher of "*" without panic
Diffstat (limited to 'modules/caddyhttp/matchers.go')
-rw-r--r--modules/caddyhttp/matchers.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index 6b57ead..988c92d 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -211,9 +211,17 @@ func (m MatchPath) Match(r *http.Request) bool {
for _, matchPath := range m {
matchPath = repl.ReplaceAll(matchPath, "")
+ // special case: whole path is wildcard; this is unnecessary
+ // as it matches all requests, which is the same as no matcher
+ if matchPath == "*" {
+ return true
+ }
+
// special case: first and last characters are wildcard,
// treat it as a fast substring match
- if strings.HasPrefix(matchPath, "*") && strings.HasSuffix(matchPath, "*") {
+ if len(matchPath) > 1 &&
+ strings.HasPrefix(matchPath, "*") &&
+ strings.HasSuffix(matchPath, "*") {
if strings.Contains(lowerPath, matchPath[1:len(matchPath)-1]) {
return true
}