mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05:00
Header matchers: allow matching presence of header with empty list
This commit is contained in:
parent
97ace2a39e
commit
f6126acf37
1 changed files with 12 additions and 2 deletions
|
@ -271,8 +271,13 @@ func (m *MatchHeader) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
// Match returns true if r matches m.
|
// Match returns true if r matches m.
|
||||||
func (m MatchHeader) Match(r *http.Request) bool {
|
func (m MatchHeader) Match(r *http.Request) bool {
|
||||||
for field, allowedFieldVals := range m {
|
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
|
var match bool
|
||||||
actualFieldVals := r.Header[textproto.CanonicalMIMEHeaderKey(field)]
|
|
||||||
fieldVals:
|
fieldVals:
|
||||||
for _, actualFieldVal := range actualFieldVals {
|
for _, actualFieldVal := range actualFieldVals {
|
||||||
for _, allowedFieldVal := range allowedFieldVals {
|
for _, allowedFieldVal := range allowedFieldVals {
|
||||||
|
@ -625,8 +630,13 @@ func (rm ResponseMatcher) matchStatusCode(statusCode int) bool {
|
||||||
|
|
||||||
func (rm ResponseMatcher) matchHeaders(hdr http.Header) bool {
|
func (rm ResponseMatcher) matchHeaders(hdr http.Header) bool {
|
||||||
for field, allowedFieldVals := range rm.Headers {
|
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
|
var match bool
|
||||||
actualFieldVals := hdr[textproto.CanonicalMIMEHeaderKey(field)]
|
|
||||||
fieldVals:
|
fieldVals:
|
||||||
for _, actualFieldVal := range actualFieldVals {
|
for _, actualFieldVal := range actualFieldVals {
|
||||||
for _, allowedFieldVal := range allowedFieldVals {
|
for _, allowedFieldVal := range allowedFieldVals {
|
||||||
|
|
Loading…
Reference in a new issue