@marcel91200 / caddy Mirror · read-only / commits / f1c36680
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

headers: Fix Caddyfile parsing for `request_header` with matchers (#4085)

Francis Lavoie committed Mar 29, 2021 at 12:55 UTC f1c36680fc8b21d5f8c110d8d3b97c4efe324376
2 files changed +94
caddytest/integration/caddyfile_adapt/request_header.txt new
+90
@@ -0,0 +1,90 @@
1 +:80
2 +
3 +@matcher path /something*
4 +request_header @matcher Denis "Ritchie"
5 +
6 +request_header +Edsger "Dijkstra"
7 +request_header -Wolfram
8 +
9 +@images path /images/*
10 +request_header @images Cache-Control "public, max-age=3600, stale-while-revalidate=86400"
11 +----------
12 +{
13 + "apps": {
14 + "http": {
15 + "servers": {
16 + "srv0": {
17 + "listen": [
18 + ":80"
19 + ],
20 + "routes": [
21 + {
22 + "match": [
23 + {
24 + "path": [
25 + "/something*"
26 + ]
27 + }
28 + ],
29 + "handle": [
30 + {
31 + "handler": "headers",
32 + "request": {
33 + "set": {
34 + "Denis": [
35 + "Ritchie"
36 + ]
37 + }
38 + }
39 + }
40 + ]
41 + },
42 + {
43 + "match": [
44 + {
45 + "path": [
46 + "/images/*"
47 + ]
48 + }
49 + ],
50 + "handle": [
51 + {
52 + "handler": "headers",
53 + "request": {
54 + "set": {
55 + "Cache-Control": [
56 + "public, max-age=3600, stale-while-revalidate=86400"
57 + ]
58 + }
59 + }
60 + }
61 + ]
62 + },
63 + {
64 + "handle": [
65 + {
66 + "handler": "headers",
67 + "request": {
68 + "add": {
69 + "Edsger": [
70 + "Dijkstra"
71 + ]
72 + }
73 + }
74 + },
75 + {
76 + "handler": "headers",
77 + "request": {
78 + "delete": [
79 + "Wolfram"
80 + ]
81 + }
82 + }
83 + ]
84 + }
85 + ]
86 + }
87 + }
88 + }
89 + }
90 +}
modules/caddyhttp/headers/caddyfile.go
+4
@@ -151,6 +151,10 @@ func parseCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
151 // request_header [<matcher>] [[+|-]<field> [<value|regexp>] [<replacement>]]
152 //
153 func parseReqHdrCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) {
154 + if !h.Next() {
155 + return nil, h.ArgErr()
156 + }
157 +
158 matcherSet, err := h.ExtractMatcherSet()
159 if err != nil {
160 return nil, err