summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-11-27 11:52:31 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2019-11-27 11:52:31 -0700
commit512b004332ebf6dfa3fd14269de3cb0031233e34 (patch)
treec73a4149bab16652f7967f05206010ec624fd84e /modules/caddyhttp
parentdb4293cb5fce33b467b50ef77698f69a4a066215 (diff)
http: header matcher supports fast prefix and suffix matching (#2888)
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/matchers.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index bddb214..508f78f 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -300,8 +300,17 @@ func (m MatchHeader) Match(r *http.Request) bool {
fieldVals:
for _, actualFieldVal := range actualFieldVals {
for _, allowedFieldVal := range allowedFieldVals {
- if actualFieldVal == allowedFieldVal {
- match = true
+ switch {
+ case strings.HasPrefix(allowedFieldVal, "*") && strings.HasSuffix(allowedFieldVal, "*"):
+ match = strings.Contains(actualFieldVal, allowedFieldVal[1:len(allowedFieldVal)-1])
+ case strings.HasPrefix(allowedFieldVal, "*"):
+ match = strings.HasSuffix(actualFieldVal, allowedFieldVal[1:])
+ case strings.HasSuffix(allowedFieldVal, "*"):
+ match = strings.HasPrefix(actualFieldVal, allowedFieldVal[:len(allowedFieldVal)-1])
+ default:
+ match = actualFieldVal == allowedFieldVal
+ }
+ if match {
break fieldVals
}
}