blob: acd2c2413ee5d01a53ebbfddfb616b4ca64a9a02 [file] [log] [blame]
Christopher Fauletcedf8fb2020-01-20 11:56:53 +01001varnishtest "Test the strict rewriting mode"
2#REQUIRE_VERSION=2.2
3
4# This config tests the strict-mode of HTTP rules.
5
6feature ignore_unknown_macro
7
8server s1 {
9 rxreq
10 txresp \
11 -status 200
12 expect req.method == "GET"
13 expect req.url == "/req1"
14 expect req.http.x-hdr1 == "123456789012345678901234567890123456789012345678901234567890"
15
16 accept
17 rxreq
18 txresp \
19 -status 200
20 expect req.method == "GET"
21 expect req.url == "/req3"
22 expect req.http.x-hdr1 == "123456789012345678901234567890123456789012345678901234567890"
23 expect req.http.x-hdr3 == <undef>
24} -start
25
26server s2 {
27 rxreq
28 txresp \
29 -status 200 \
30 -hdr "x-req: /req1" \
31 -bodylen 2000
32 expect req.method == "GET"
33 expect req.url == "/req1"
34
35 accept
36 rxreq
37 txresp \
38 -status 200 \
39 -hdr "x-req: /req2" \
40 -bodylen 2000
41 expect req.method == "GET"
42 expect req.url == "/req2"
43
44 accept
45 rxreq
46 txresp \
47 -status 200 \
48 -hdr "x-req: /req3" \
49 -bodylen 2000
50 expect req.method == "GET"
51 expect req.url == "/req3"
52
53 accept
54 rxreq
55 txresp \
56 -status 200 \
57 -hdr "x-req: /req4" \
58 -bodylen 2000
59 expect req.method == "GET"
60 expect req.url == "/req4"
61
62} -start
63
64haproxy h1 -conf {
65 global
66 tune.bufsize 2048
67 tune.maxrewrite 128
68
69 defaults
70 mode http
71 timeout connect 1s
72 timeout client 1s
73 timeout server 1s
74 option http-buffer-request
75
76 frontend fe1
77 bind "fd@${fe1}"
78 http-request set-header x-hdr1 123456789012345678901234567890123456789012345678901234567890
79 http-request set-header x-hdr2 123456789012345678901234567890123456789012345678901234567890 if { path /req2 }
80 http-request strict-mode off if { path /req3 }
81 http-request set-header x-hdr3 123456789012345678901234567890123456789012345678901234567890 if { path /req3 }
82 default_backend be1
83
84 backend be1
85 http-request set-header x-hdr3 123456789012345678901234567890123456789012345678901234567890 if { path /req4 }
86 server s1 ${s1_addr}:${s1_port}
87
88 frontend fe2
89 bind "fd@${fe2}"
90 http-response set-header x-hdr4 123456789012345678901234567890123456789012345678901234567890 if { res.hdr(x-req) /req4 }
91 default_backend be2
92 backend be2
93 http-response set-header x-hdr1 123456789012345678901234567890123456789012345678901234567890
94 http-response set-header x-hdr2 123456789012345678901234567890123456789012345678901234567890 if { res.hdr(x-req) /req2 }
95 http-response strict-mode off if { res.hdr(x-req) /req3 }
96 http-response set-header x-hdr3 123456789012345678901234567890123456789012345678901234567890 if { res.hdr(-req) /req3 }
97 server s2 ${s2_addr}:${s2_port}
98
99} -start
100
101client c1r1 -connect ${h1_fe1_sock} {
102 txreq \
103 -req GET \
104 -url /req1 \
105 -bodylen 2000
106 rxresp
107 expect resp.status == 200
108} -run
109client c1r2 -connect ${h1_fe1_sock} {
110 txreq \
111 -req GET \
112 -url /req2 \
113 -bodylen 2000
114 rxresp
115 expect resp.status == 500
116} -run
117client c1r3 -connect ${h1_fe1_sock} {
118 txreq \
119 -req GET \
120 -url /req3 \
121 -bodylen 2000
122 rxresp
123 expect resp.status == 200
124} -run
125client c1r4 -connect ${h1_fe1_sock} {
126 txreq \
127 -req GET \
128 -url /req4 \
129 -bodylen 2000
130 rxresp
131 expect resp.status == 500
132} -run
133
134client c2r1 -connect ${h1_fe2_sock} {
135 txreq \
136 -req GET \
137 -url /req1
138 rxresp
139 expect resp.status == 200
140 expect resp.http.x-hdr1 == "123456789012345678901234567890123456789012345678901234567890"
141} -run
142client c2r2 -connect ${h1_fe2_sock} {
143 txreq \
144 -req GET \
145 -url /req2
146 rxresp
147 expect resp.status == 500
148} -run
149client c2r3 -connect ${h1_fe2_sock} {
150 txreq \
151 -req GET \
152 -url /req3
153 rxresp
154 expect resp.status == 200
155 expect resp.http.x-hdr1 == "123456789012345678901234567890123456789012345678901234567890"
156 expect resp.http.x-hdr3 == <undef>
157} -run
158client c2r4 -connect ${h1_fe2_sock} {
159 txreq \
160 -req GET \
161 -url /req4
162 rxresp
163 expect resp.status == 500
164} -run