diff options
author | Francis Lavoie <[email protected]> | 2021-03-29 12:55:29 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-29 10:55:29 -0600 |
commit | f1c36680fc8b21d5f8c110d8d3b97c4efe324376 (patch) | |
tree | a74ce558a39eeb4f538f65a7d4d34887865b3c57 | |
parent | a87f757fccabfbaa7c8f80b1acd5faaf8d7d6297 (diff) | |
download | caddy-f1c36680fc8b21d5f8c110d8d3b97c4efe324376.tar.gz caddy-f1c36680fc8b21d5f8c110d8d3b97c4efe324376.zip |
headers: Fix Caddyfile parsing for `request_header` with matchers (#4085)
-rw-r--r-- | caddytest/integration/caddyfile_adapt/request_header.txt | 90 | ||||
-rw-r--r-- | modules/caddyhttp/headers/caddyfile.go | 4 |
2 files changed, 94 insertions, 0 deletions
diff --git a/caddytest/integration/caddyfile_adapt/request_header.txt b/caddytest/integration/caddyfile_adapt/request_header.txt new file mode 100644 index 000000000..bab3fcac5 --- /dev/null +++ b/caddytest/integration/caddyfile_adapt/request_header.txt @@ -0,0 +1,90 @@ +:80 + +@matcher path /something* +request_header @matcher Denis "Ritchie" + +request_header +Edsger "Dijkstra" +request_header -Wolfram + +@images path /images/* +request_header @images Cache-Control "public, max-age=3600, stale-while-revalidate=86400" +---------- +{ + "apps": { + "http": { + "servers": { + "srv0": { + "listen": [ + ":80" + ], + "routes": [ + { + "match": [ + { + "path": [ + "/something*" + ] + } + ], + "handle": [ + { + "handler": "headers", + "request": { + "set": { + "Denis": [ + "Ritchie" + ] + } + } + } + ] + }, + { + "match": [ + { + "path": [ + "/images/*" + ] + } + ], + "handle": [ + { + "handler": "headers", + "request": { + "set": { + "Cache-Control": [ + "public, max-age=3600, stale-while-revalidate=86400" + ] + } + } + } + ] + }, + { + "handle": [ + { + "handler": "headers", + "request": { + "add": { + "Edsger": [ + "Dijkstra" + ] + } + } + }, + { + "handler": "headers", + "request": { + "delete": [ + "Wolfram" + ] + } + } + ] + } + ] + } + } + } + } +} diff --git a/modules/caddyhttp/headers/caddyfile.go b/modules/caddyhttp/headers/caddyfile.go index 574e54bbd..c6ea2fb03 100644 --- a/modules/caddyhttp/headers/caddyfile.go +++ b/modules/caddyhttp/headers/caddyfile.go @@ -151,6 +151,10 @@ func parseCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) // request_header [<matcher>] [[+|-]<field> [<value|regexp>] [<replacement>]] // func parseReqHdrCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) { + if !h.Next() { + return nil, h.ArgErr() + } + matcherSet, err := h.ExtractMatcherSet() if err != nil { return nil, err |