func matchHeaders(input, against http.Header, host string, repl *caddy.Replacer) bool {
	for field, allowedFieldVals := range against {
		actualFieldVals := getHeaderFieldVals(input, field, host)
		if allowedFieldVals != nil && len(allowedFieldVals) == 0 && actualFieldVals != nil {
			// a non-nil but empty list of allowed values means
			// match if the header field exists at all
			continue
		}
		if allowedFieldVals == nil && actualFieldVals == nil {
			// a nil list means match if the header does not exist at all
			continue
		}
		var match bool
	fieldVals:
		for _, actualFieldVal := range actualFieldVals {
			for _, allowedFieldVal := range allowedFieldVals {
				if repl != nil {
					allowedFieldVal = repl.ReplaceAll(allowedFieldVal, "")
				}
				switch {
				case allowedFieldVal == "*":
					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
				}
			}
		}
		if !match {
			return false
		}
	}
	return true
}
// matchHeaders returns true if input matches the criteria in against without regex.
// The host parameter should be obtained from the http.Request.Host field since
// net/http removes it from the header map.
matchHeaders returns true if input matches the criteria in against without regex.
The host parameter should be obtained from the http.Request.Host field since
net/http removes it from the header map.
// matchHeaders returns true if input matches the criteria in against without regex . // The host parameter should be obtained from the http . Request . Host field since // net / http removes it from the header map .
func matchHeaders(input, against http.Header, host string, repl *caddy.Replacer) bool {
	for field, allowedFieldVals := range against {
		actualFieldVals := getHeaderFieldVals(input, field, host)
		if allowedFieldVals != nil && len(allowedFieldVals) == 0 && actualFieldVals != nil {
			continue
		}
		if allowedFieldVals == nil && actualFieldVals == nil {
			continue
		}
		var match bool
	fieldVals:
		for _, actualFieldVal := range actualFieldVals {
			for _, allowedFieldVal := range allowedFieldVals {
				if repl != nil {
					allowedFieldVal = repl.ReplaceAll(allowedFieldVal, "")
				}
				switch {
				case allowedFieldVal == "*":
					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
				}
			}
		}
		if !match {
			return false
		}
	}
	return true
}
func matchHeaders ( input , against http . Header , host string , repl * caddy . Replacer ) bool { for field , allowedFieldVals := range against { actualFieldVals := getHeaderFieldVals ( input , field , host ) if allowedFieldVals != nil && len ( allowedFieldVals ) == 0 && actualFieldVals != nil { continue } if allowedFieldVals == nil && actualFieldVals == nil { continue } var match bool fieldVals : for _ , actualFieldVal := range actualFieldVals { for _ , allowedFieldVal := range allowedFieldVals { if repl != nil { allowedFieldVal = repl . ReplaceAll ( allowedFieldVal , " " ) } switch { case allowedFieldVal == " " : 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 } } } if ! match { return false } } return true }
matchHeaders returns true if input matches the criteria in against without regex.
matchHeaders returns true if input matches the criteria in against without regex .
// a non-nil but empty list of allowed values means // match if the header field exists at all // a nil list means match if the header does not exist at all