summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-09-06 14:25:16 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-09-06 14:25:16 -0600
commitf6126acf379963136a6caeb818296a7510abd532 (patch)
treec8d794581c3a5e28a7c9cf0df131ee4d8bc42a30
parent97ace2a39e058f435d4e6adbee874eaabb42e45d (diff)
Header matchers: allow matching presence of header with empty list
-rw-r--r--modules/caddyhttp/matchers.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index 7fc8aea..4d0eea5 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -271,8 +271,13 @@ func (m *MatchHeader) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// Match returns true if r matches m.
func (m MatchHeader) Match(r *http.Request) bool {
for field, allowedFieldVals := range m {
+ actualFieldVals, fieldExists := r.Header[textproto.CanonicalMIMEHeaderKey(field)]
+ if allowedFieldVals != nil && len(allowedFieldVals) == 0 && fieldExists {
+ // a non-nil but empty list of allowed values means
+ // match if the header field exists at all
+ continue
+ }
var match bool
- actualFieldVals := r.Header[textproto.CanonicalMIMEHeaderKey(field)]
fieldVals:
for _, actualFieldVal := range actualFieldVals {
for _, allowedFieldVal := range allowedFieldVals {
@@ -625,8 +630,13 @@ func (rm ResponseMatcher) matchStatusCode(statusCode int) bool {
func (rm ResponseMatcher) matchHeaders(hdr http.Header) bool {
for field, allowedFieldVals := range rm.Headers {
+ actualFieldVals, fieldExists := hdr[textproto.CanonicalMIMEHeaderKey(field)]
+ if allowedFieldVals != nil && len(allowedFieldVals) == 0 && fieldExists {
+ // a non-nil but empty list of allowed values means
+ // match if the header field exists at all
+ continue
+ }
var match bool
- actualFieldVals := hdr[textproto.CanonicalMIMEHeaderKey(field)]
fieldVals:
for _, actualFieldVal := range actualFieldVals {
for _, allowedFieldVal := range allowedFieldVals {