Francis Lavoie
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
38 additions and
1 deletions
-
caddytest/integration/caddyfile_adapt/matcher_syntax.txt
-
modules/caddyhttp/matchers.go
|
@ -18,6 +18,13 @@ |
|
|
|
|
|
|
|
|
@matcher6 vars_regexp "{http.request.uri}" `\.([a-f0-9]{6})\.(css|js)$` |
|
|
@matcher6 vars_regexp "{http.request.uri}" `\.([a-f0-9]{6})\.(css|js)$` |
|
|
respond @matcher6 "from vars_regexp matcher without name" |
|
|
respond @matcher6 "from vars_regexp matcher without name" |
|
|
|
|
|
|
|
|
|
|
|
@matcher7 { |
|
|
|
|
|
header Foo bar |
|
|
|
|
|
header Foo foobar |
|
|
|
|
|
header Bar foo |
|
|
|
|
|
} |
|
|
|
|
|
respond @matcher7 "header matcher merging values of the same field" |
|
|
} |
|
|
} |
|
|
---------- |
|
|
---------- |
|
|
{ |
|
|
{ |
|
@ -127,6 +134,27 @@ |
|
|
"handler": "static_response" |
|
|
"handler": "static_response" |
|
|
} |
|
|
} |
|
|
] |
|
|
] |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
"match": [ |
|
|
|
|
|
{ |
|
|
|
|
|
"header": { |
|
|
|
|
|
"Bar": [ |
|
|
|
|
|
"foo" |
|
|
|
|
|
], |
|
|
|
|
|
"Foo": [ |
|
|
|
|
|
"bar", |
|
|
|
|
|
"foobar" |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
], |
|
|
|
|
|
"handle": [ |
|
|
|
|
|
{ |
|
|
|
|
|
"body": "header matcher merging values of the same field", |
|
|
|
|
|
"handler": "static_response" |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
} |
|
|
} |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
|
@ -408,7 +408,16 @@ func (m *MatchHeader) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { |
|
|
if !d.Args(&field, &val) { |
|
|
if !d.Args(&field, &val) { |
|
|
return d.Errf("malformed header matcher: expected both field and value") |
|
|
return d.Errf("malformed header matcher: expected both field and value") |
|
|
} |
|
|
} |
|
|
http.Header(*m).Set(field, val) |
|
|
|
|
|
|
|
|
// If multiple header matchers with the same header field are defined,
|
|
|
|
|
|
// we want to add the existing to the list of headers (will be OR'ed)
|
|
|
|
|
|
existing := http.Header(*m).Values(field) |
|
|
|
|
|
if len(existing) > 0 { |
|
|
|
|
|
http.Header(*m).Add(field, val) |
|
|
|
|
|
} else { |
|
|
|
|
|
http.Header(*m).Set(field, val) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if d.NextBlock(0) { |
|
|
if d.NextBlock(0) { |
|
|
return d.Err("malformed header matcher: blocks are not supported") |
|
|
return d.Err("malformed header matcher: blocks are not supported") |
|
|
} |
|
|
} |
|
|