mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
http: header matcher supports fast prefix and suffix matching (#2888)
This commit is contained in:
parent
db4293cb5f
commit
512b004332
1 changed files with 11 additions and 2 deletions
|
@ -300,8 +300,17 @@ func (m MatchHeader) Match(r *http.Request) bool {
|
||||||
fieldVals:
|
fieldVals:
|
||||||
for _, actualFieldVal := range actualFieldVals {
|
for _, actualFieldVal := range actualFieldVals {
|
||||||
for _, allowedFieldVal := range allowedFieldVals {
|
for _, allowedFieldVal := range allowedFieldVals {
|
||||||
if actualFieldVal == allowedFieldVal {
|
switch {
|
||||||
match = true
|
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
|
break fieldVals
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue