blob: 90834c562f029d96afad7ec1d4bccb1f39d1604c [file] [log] [blame]
Willy Tarreau12989482018-12-07 18:21:21 +01001varnishtest "Composite HTTP manipulation test (H1 and H2 clear to H1 clear)"
Willy Tarreau12989482018-12-07 18:21:21 +01002
3# This config tests several http-request features and their interactions.
4# It extracts some samples, places them into variables, modifies some header
5# fields, appends multiple identical header fields, overwrites the start line
6# using several methods, then dumps the initial list of variables and the final
7# one, then applies CRC32 to these values as signatures that are easy to test.
8# Then it does it again in the backend after saving the current headers into
9# the same names prefixed by "fe-". Then it does the same on the response path.
10# If some modifications are performed, the crc values need to be adjusted based
11# on the failed logs.
12#
13# Run it with HAPROXY_PROGRAM=$PWD/haproxy varnishtest -l -k -t 1 "$1"
14
15feature ignore_unknown_macro
16
17server s1 {
18 rxreq
19 txresp \
20 -status 234 \
21 -hdr "hdr1: val1" \
22 -hdr "hdr2: val2a" \
23 -hdr "hdr2: val2b" \
24 -hdr "hdr3: val3a, val3b" \
25 -hdr "hdr4:" \
Willy Tarreau12989482018-12-07 18:21:21 +010026 -body "This is a body"
27
28 expect req.method == "GET"
29 expect req.http.fe-sl1-crc == 992395575
30 expect req.http.fe-sl2-crc == 1270056220
31 expect req.http.fe-hdr-crc == 1719311923
32 expect req.http.be-sl1-crc == 2604236007
33 expect req.http.be-sl2-crc == 4181358964
34 expect req.http.be-hdr-crc == 3634102538
35} -repeat 2 -start
36
37haproxy h1 -conf {
38 defaults
39 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +010040 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
41 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
42 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
Willy Tarreau12989482018-12-07 18:21:21 +010043
44 frontend fe
45 bind "fd@${feh1}"
46 bind "fd@${feh2}" proto h2
47
48 #### requests
49 http-request set-var(req.method) method
50 http-request set-var(req.uri) url
51 http-request set-var(req.path) path
52 http-request set-var(req.query) query
53 http-request set-var(req.param) url_param(qs_arg)
54
55 http-request set-header sl1 "sl1: "
56
57 http-request set-method "%[str(GET)]"
Christopher Faulet95d169b2020-01-17 23:21:59 +010058 http-request set-uri %[str(),concat(/bu/,req.uri,/eu)]
Willy Tarreau12989482018-12-07 18:21:21 +010059 http-request set-path "/bp/%[var(req.path)]/ep"
60 http-request set-query "bq&%[var(req.query)]&eq"
61
62 http-request set-header sl2 "sl2: "
63
64 http-request set-header sl1 "%[req.fhdr(sl1)] method=<%[var(req.method)]>; uri=<%[var(req.uri)]>; path=<%[var(req.path)]>;"
65 http-request set-header sl1 "%[req.fhdr(sl1)] query=<%[var(req.query)]>; param=<%[var(req.param)]>"
66 http-request set-header sl2 "%[req.fhdr(sl2)] method=<%[method]>; uri=<%[url]>; path=<%[path]>; "
67 http-request set-header sl2 "%[req.fhdr(sl2)] query=<%[query]>; param=<%[url_param(qs_arg)]>"
68 http-request set-header hdr "%[req.fhdr(hdr)] hdr1=<%[req.hdr(hdr1)]>; fhdr1=<%[req.fhdr(hdr1)]>;"
69 http-request set-header hdr "%[req.fhdr(hdr)] hdr2=<%[req.hdr(hdr2)]>; fhdr2=<%[req.fhdr(hdr2)]>;"
70 http-request set-header hdr "%[req.fhdr(hdr)] hdr3=<%[req.hdr(hdr3)]>; fhdr3=<%[req.fhdr(hdr3)]>;"
71 http-request set-header hdr "%[req.fhdr(hdr)] hdr4=<%[req.hdr(hdr4)]>; fhdr4=<%[req.fhdr(hdr4)]>;"
72
73 http-request set-header sl1-crc "%[req.fhdr(sl1),crc32]"
74 http-request set-header sl2-crc "%[req.fhdr(sl2),crc32]"
75 http-request set-header hdr-crc "%[req.fhdr(hdr),crc32]"
76
77 #### responses
78 http-response set-header be-sl1 "%[res.fhdr(sl1)]"
79 http-response set-header be-sl2 "%[res.fhdr(sl2)]"
80 http-response set-header be-hdr "%[res.fhdr(hdr)]"
81
82 http-response set-header be-sl1-crc "%[res.fhdr(sl1-crc)]"
83 http-response set-header be-sl2-crc "%[res.fhdr(sl2-crc)]"
84 http-response set-header be-hdr-crc "%[res.fhdr(hdr-crc)]"
85
86 http-response set-var(res.status) status
87 http-response set-header sl1 "sl1: "
88
89 http-response set-status 200
90
91 http-response set-header sl2 "sl2: "
92
93 http-response set-header sl1 "%[res.fhdr(sl1)] status=<%[var(res.status)]>;"
94 http-response set-header sl2 "%[res.fhdr(sl2)] status=<%[status]>;"
95 http-response set-header hdr "%[res.fhdr(hdr)] hdr1=<%[res.hdr(hdr1)]>; fhdr1=<%[res.fhdr(hdr1)]>;"
96 http-response set-header hdr "%[res.fhdr(hdr)] hdr2=<%[res.hdr(hdr2)]>; fhdr2=<%[res.fhdr(hdr2)]>;"
97 http-response set-header hdr "%[res.fhdr(hdr)] hdr3=<%[res.hdr(hdr3)]>; fhdr3=<%[res.fhdr(hdr3)]>;"
98 http-response set-header hdr "%[res.fhdr(hdr)] hdr4=<%[res.hdr(hdr4)]>; fhdr4=<%[res.fhdr(hdr4)]>;"
99
100 http-response set-header fe-sl1-crc "%[res.fhdr(sl1),crc32]"
101 http-response set-header fe-sl2-crc "%[res.fhdr(sl2),crc32]"
102 http-response set-header fe-hdr-crc "%[res.fhdr(hdr),crc32]"
103
104 default_backend be
105
106 backend be
107 #### requests
108 http-request set-header fe-sl1 "%[req.fhdr(sl1)]"
109 http-request set-header fe-sl2 "%[req.fhdr(sl2)]"
110 http-request set-header fe-hdr "%[req.fhdr(hdr)]"
111
112 http-request set-header fe-sl1-crc "%[req.fhdr(sl1-crc)]"
113 http-request set-header fe-sl2-crc "%[req.fhdr(sl2-crc)]"
114 http-request set-header fe-hdr-crc "%[req.fhdr(hdr-crc)]"
115
116 http-request set-var(req.method) method
117 http-request set-var(req.uri) url
118 http-request set-var(req.path) path
119 http-request set-var(req.query) query
120 http-request set-var(req.param) url_param(qs_arg)
121
122 http-request set-header sl1 "sl1: "
123
124 http-request set-method "%[str(GET)]"
Christopher Faulet95d169b2020-01-17 23:21:59 +0100125 http-request set-uri %[str(),concat(/bu/,req.uri,/eu)]
Willy Tarreau12989482018-12-07 18:21:21 +0100126 http-request set-path "/bp/%[var(req.path)]/ep"
127 http-request set-query "bq&%[var(req.query)]&eq"
128
129 http-request set-header sl2 "sl2: "
130
131 http-request set-header sl1 "%[req.fhdr(sl1)] method=<%[var(req.method)]>; uri=<%[var(req.uri)]>; path=<%[var(req.path)]>;"
132 http-request set-header sl1 "%[req.fhdr(sl1)] query=<%[var(req.query)]>; param=<%[var(req.param)]>"
133 http-request set-header sl2 "%[req.fhdr(sl2)] method=<%[method]>; uri=<%[url]>; path=<%[path]>; "
Martin DOLEZd3e58f82023-03-30 09:03:36 -0400134 http-request set-header sl2 "%[req.fhdr(sl2)] query=<%[query]>; param=<%[url_param(QS_arg,,i)]>"
Willy Tarreau12989482018-12-07 18:21:21 +0100135 http-request set-header hdr "%[req.fhdr(hdr)] hdr1=<%[req.hdr(hdr1)]>; fhdr1=<%[req.fhdr(hdr1)]>;"
136 http-request set-header hdr "%[req.fhdr(hdr)] hdr2=<%[req.hdr(hdr2)]>; fhdr2=<%[req.fhdr(hdr2)]>;"
137 http-request set-header hdr "%[req.fhdr(hdr)] hdr3=<%[req.hdr(hdr3)]>; fhdr3=<%[req.fhdr(hdr3)]>;"
138 http-request set-header hdr "%[req.fhdr(hdr)] hdr4=<%[req.hdr(hdr4)]>; fhdr4=<%[req.fhdr(hdr4)]>;"
139
140 http-request set-header be-sl1-crc "%[req.fhdr(sl1),crc32]"
141 http-request set-header be-sl2-crc "%[req.fhdr(sl2),crc32]"
142 http-request set-header be-hdr-crc "%[req.fhdr(hdr),crc32]"
143
144 #### responses
145 http-response set-var(res.status) status
146 http-response set-header sl1 "sl1: "
147
148 http-response set-status 200
149
150 http-response set-header sl2 "sl2: "
151
152 http-response set-header sl1 "%[res.fhdr(sl1)] status=<%[var(res.status)]>;"
153 http-response set-header sl2 "%[res.fhdr(sl2)] status=<%[status]>;"
154 http-response set-header hdr "%[res.fhdr(hdr)] hdr1=<%[res.hdr(hdr1)]>; fhdr1=<%[res.fhdr(hdr1)]>;"
155 http-response set-header hdr "%[res.fhdr(hdr)] hdr2=<%[res.hdr(hdr2)]>; fhdr2=<%[res.fhdr(hdr2)]>;"
156 http-response set-header hdr "%[res.fhdr(hdr)] hdr3=<%[res.hdr(hdr3)]>; fhdr3=<%[res.fhdr(hdr3)]>;"
157 http-response set-header hdr "%[res.fhdr(hdr)] hdr4=<%[res.hdr(hdr4)]>; fhdr4=<%[res.fhdr(hdr4)]>;"
158
159 http-response set-header sl1-crc "%[res.fhdr(sl1),crc32]"
160 http-response set-header sl2-crc "%[res.fhdr(sl2),crc32]"
161 http-response set-header hdr-crc "%[res.fhdr(hdr),crc32]"
Christopher Faulet46f46df2021-11-09 16:33:25 +0100162 http-response allow
163 http-response deny # must not be evaluated
Willy Tarreau12989482018-12-07 18:21:21 +0100164
165 server s1 ${s1_addr}:${s1_port}
166} -start
167
168client c1h1 -connect ${h1_feh1_sock} {
169 txreq \
170 -req GET \
171 -url /path/to/file.extension?qs_arg=qs_value \
172 -hdr "hdr1: val1" \
173 -hdr "hdr2: val2a" \
174 -hdr "hdr2: val2b" \
175 -hdr "hdr3: val3a, val3b" \
176 -hdr "hdr4:"
177 rxresp
178
179 expect resp.status == 200
180 expect resp.http.be-sl1-crc == 487202719
181 expect resp.http.be-sl2-crc == 561949791
182 expect resp.http.be-hdr-crc == 1719311923
183 expect resp.http.fe-sl1-crc == 146151597
184 expect resp.http.fe-sl2-crc == 561949791
185 expect resp.http.fe-hdr-crc == 3634102538
186 expect resp.bodylen == 14
187 expect resp.body == "This is a body"
188} -run
189
190client c1h2 -connect ${h1_feh2_sock} {
Willy Tarreau211d5402018-12-13 17:29:20 +0100191 txpri
192 stream 0 {
193 txsettings
194 rxsettings
195 txsettings -ack
Willy Tarreau211d5402018-12-13 17:29:20 +0100196 rxsettings
197 expect settings.ack == true
198 } -run
Willy Tarreau12989482018-12-07 18:21:21 +0100199 stream 1 {
200 # warning: -req, -scheme, -url MUST be placed first otherwise
201 # the H2 protocol is invalid since they are pseudo-headers
202 txreq \
203 -req GET \
204 -scheme "https" \
205 -url /path/to/file.extension?qs_arg=qs_value \
206 -hdr "hdr1" "val1" \
207 -hdr "hdr2" " val2a" \
208 -hdr "hdr2" " val2b" \
209 -hdr "hdr3" " val3a, val3b" \
210 -hdr "hdr4" ""
211
212 rxhdrs
213 expect resp.status == 200
214 expect resp.http.be-sl1-crc == 487202719
215 expect resp.http.be-sl2-crc == 561949791
216 expect resp.http.be-hdr-crc == 1719311923
217 expect resp.http.fe-sl1-crc == 146151597
218 expect resp.http.fe-sl2-crc == 561949791
219 expect resp.http.fe-hdr-crc == 3634102538
220 expect resp.http.content-length == 14
221
222 rxdata -all
223 expect resp.body == "This is a body"
224 } -run
225} -run