http: header matcher supports fast prefix and suffix matching (#2888)

This commit is contained in:
Matthew Holt 2019-11-27 11:52:31 -07:00
parent db4293cb5f
commit 512b004332
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5

View file

@ -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
}
}