@marcel91200 / caddy Mirror · read-only / commits / f6126acf
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

Header matchers: allow matching presence of header with empty list

Matthew Holt committed Sep 6, 2019 at 14:25 UTC f6126acf379963136a6caeb818296a7510abd532
1 file changed +12 -2
modules/caddyhttp/matchers.go
+12 -2
@@ -271,8 +271,13 @@ func (m *MatchHeader) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
271 // Match returns true if r matches m.
272 func (m MatchHeader) Match(r *http.Request) bool {
273 for field, allowedFieldVals := range m {
274 + actualFieldVals, fieldExists := r.Header[textproto.CanonicalMIMEHeaderKey(field)]
275 + if allowedFieldVals != nil && len(allowedFieldVals) == 0 && fieldExists {
276 + // a non-nil but empty list of allowed values means
277 + // match if the header field exists at all
278 + continue
279 + }
280 var match bool
275 - actualFieldVals := r.Header[textproto.CanonicalMIMEHeaderKey(field)]
281 fieldVals:
282 for _, actualFieldVal := range actualFieldVals {
283 for _, allowedFieldVal := range allowedFieldVals {
@@ -625,8 +630,13 @@ func (rm ResponseMatcher) matchStatusCode(statusCode int) bool {
630
631 func (rm ResponseMatcher) matchHeaders(hdr http.Header) bool {
632 for field, allowedFieldVals := range rm.Headers {
633 + actualFieldVals, fieldExists := hdr[textproto.CanonicalMIMEHeaderKey(field)]
634 + if allowedFieldVals != nil && len(allowedFieldVals) == 0 && fieldExists {
635 + // a non-nil but empty list of allowed values means
636 + // match if the header field exists at all
637 + continue
638 + }
639 var match bool
629 - actualFieldVals := hdr[textproto.CanonicalMIMEHeaderKey(field)]
640 fieldVals:
641 for _, actualFieldVal := range actualFieldVals {
642 for _, allowedFieldVal := range allowedFieldVals {