blob: 7490172208bb83d977cd2a90c28866ee7fc40ac3 [file] [log] [blame]
Willy Tarreau12989482018-12-07 18:21:21 +01001varnishtest "Composite HTTP manipulation test (H1 and H2 clear to H1 clear)"
2#REQUIRE_VERSION=1.9
3
4# This config tests several http-request features and their interactions.
5# It extracts some samples, places them into variables, modifies some header
6# fields, appends multiple identical header fields, overwrites the start line
7# using several methods, then dumps the initial list of variables and the final
8# one, then applies CRC32 to these values as signatures that are easy to test.
9# Then it does it again in the backend after saving the current headers into
10# the same names prefixed by "fe-". Then it does the same on the response path.
11# If some modifications are performed, the crc values need to be adjusted based
12# on the failed logs.
13#
14# Run it with HAPROXY_PROGRAM=$PWD/haproxy varnishtest -l -k -t 1 "$1"
15
16feature ignore_unknown_macro
17
18server s1 {
19 rxreq
20 txresp \
21 -status 234 \
22 -hdr "hdr1: val1" \
23 -hdr "hdr2: val2a" \
24 -hdr "hdr2: val2b" \
25 -hdr "hdr3: val3a, val3b" \
26 -hdr "hdr4:" \
Willy Tarreau12989482018-12-07 18:21:21 +010027 -body "This is a body"
28
29 expect req.method == "GET"
Willy Tarreauc48acd12023-08-09 11:02:34 +020030 expect req.http.fe-sl1-crc == 1874847043
31 expect req.http.fe-sl2-crc == 1142278307
Willy Tarreau12989482018-12-07 18:21:21 +010032 expect req.http.fe-hdr-crc == 1719311923
Willy Tarreauc48acd12023-08-09 11:02:34 +020033 expect req.http.be-sl1-crc == 3455320059
34 expect req.http.be-sl2-crc == 2509326257
Willy Tarreau12989482018-12-07 18:21:21 +010035 expect req.http.be-hdr-crc == 3634102538
36} -repeat 2 -start
37
38haproxy h1 -conf {
39 defaults
40 mode http
Christopher Faulet8f161482018-12-19 11:49:39 +010041 ${no-htx} option http-use-htx
Willy Tarreau12989482018-12-07 18:21:21 +010042 timeout connect 1s
43 timeout client 1s
44 timeout server 1s
45
46 frontend fe
47 bind "fd@${feh1}"
48 bind "fd@${feh2}" proto h2
49
50 #### requests
51 http-request set-var(req.method) method
52 http-request set-var(req.uri) url
53 http-request set-var(req.path) path
54 http-request set-var(req.query) query
55 http-request set-var(req.param) url_param(qs_arg)
Willy Tarreauc48acd12023-08-09 11:02:34 +020056 http-request set-var(req.cl) req.fhdr(content-length)
Willy Tarreau12989482018-12-07 18:21:21 +010057
58 http-request set-header sl1 "sl1: "
59
60 http-request set-method "%[str(GET)]"
Christopher Faulet95d169b2020-01-17 23:21:59 +010061 http-request set-uri %[str(),concat(/bu/,req.uri,/eu)]
Willy Tarreau12989482018-12-07 18:21:21 +010062 http-request set-path "/bp/%[var(req.path)]/ep"
63 http-request set-query "bq&%[var(req.query)]&eq"
64
65 http-request set-header sl2 "sl2: "
66
67 http-request set-header sl1 "%[req.fhdr(sl1)] method=<%[var(req.method)]>; uri=<%[var(req.uri)]>; path=<%[var(req.path)]>;"
68 http-request set-header sl1 "%[req.fhdr(sl1)] query=<%[var(req.query)]>; param=<%[var(req.param)]>"
Willy Tarreauc48acd12023-08-09 11:02:34 +020069 http-request set-header sl1 "%[req.fhdr(sl1)] cl=<%[var(req.cl)]>"
Willy Tarreau12989482018-12-07 18:21:21 +010070 http-request set-header sl2 "%[req.fhdr(sl2)] method=<%[method]>; uri=<%[url]>; path=<%[path]>; "
71 http-request set-header sl2 "%[req.fhdr(sl2)] query=<%[query]>; param=<%[url_param(qs_arg)]>"
Willy Tarreauc48acd12023-08-09 11:02:34 +020072 http-request set-header sl2 "%[req.fhdr(sl2)] cl=<%[req.fhdr(content-length)]>"
Willy Tarreau12989482018-12-07 18:21:21 +010073 http-request set-header hdr "%[req.fhdr(hdr)] hdr1=<%[req.hdr(hdr1)]>; fhdr1=<%[req.fhdr(hdr1)]>;"
74 http-request set-header hdr "%[req.fhdr(hdr)] hdr2=<%[req.hdr(hdr2)]>; fhdr2=<%[req.fhdr(hdr2)]>;"
75 http-request set-header hdr "%[req.fhdr(hdr)] hdr3=<%[req.hdr(hdr3)]>; fhdr3=<%[req.fhdr(hdr3)]>;"
76 http-request set-header hdr "%[req.fhdr(hdr)] hdr4=<%[req.hdr(hdr4)]>; fhdr4=<%[req.fhdr(hdr4)]>;"
77
78 http-request set-header sl1-crc "%[req.fhdr(sl1),crc32]"
79 http-request set-header sl2-crc "%[req.fhdr(sl2),crc32]"
80 http-request set-header hdr-crc "%[req.fhdr(hdr),crc32]"
81
82 #### responses
83 http-response set-header be-sl1 "%[res.fhdr(sl1)]"
84 http-response set-header be-sl2 "%[res.fhdr(sl2)]"
85 http-response set-header be-hdr "%[res.fhdr(hdr)]"
86
87 http-response set-header be-sl1-crc "%[res.fhdr(sl1-crc)]"
88 http-response set-header be-sl2-crc "%[res.fhdr(sl2-crc)]"
89 http-response set-header be-hdr-crc "%[res.fhdr(hdr-crc)]"
90
91 http-response set-var(res.status) status
92 http-response set-header sl1 "sl1: "
93
94 http-response set-status 200
95
96 http-response set-header sl2 "sl2: "
97
98 http-response set-header sl1 "%[res.fhdr(sl1)] status=<%[var(res.status)]>;"
99 http-response set-header sl2 "%[res.fhdr(sl2)] status=<%[status]>;"
100 http-response set-header hdr "%[res.fhdr(hdr)] hdr1=<%[res.hdr(hdr1)]>; fhdr1=<%[res.fhdr(hdr1)]>;"
101 http-response set-header hdr "%[res.fhdr(hdr)] hdr2=<%[res.hdr(hdr2)]>; fhdr2=<%[res.fhdr(hdr2)]>;"
102 http-response set-header hdr "%[res.fhdr(hdr)] hdr3=<%[res.hdr(hdr3)]>; fhdr3=<%[res.fhdr(hdr3)]>;"
103 http-response set-header hdr "%[res.fhdr(hdr)] hdr4=<%[res.hdr(hdr4)]>; fhdr4=<%[res.fhdr(hdr4)]>;"
104
105 http-response set-header fe-sl1-crc "%[res.fhdr(sl1),crc32]"
106 http-response set-header fe-sl2-crc "%[res.fhdr(sl2),crc32]"
107 http-response set-header fe-hdr-crc "%[res.fhdr(hdr),crc32]"
108
109 default_backend be
110
111 backend be
112 #### requests
113 http-request set-header fe-sl1 "%[req.fhdr(sl1)]"
114 http-request set-header fe-sl2 "%[req.fhdr(sl2)]"
115 http-request set-header fe-hdr "%[req.fhdr(hdr)]"
116
117 http-request set-header fe-sl1-crc "%[req.fhdr(sl1-crc)]"
118 http-request set-header fe-sl2-crc "%[req.fhdr(sl2-crc)]"
119 http-request set-header fe-hdr-crc "%[req.fhdr(hdr-crc)]"
120
121 http-request set-var(req.method) method
122 http-request set-var(req.uri) url
123 http-request set-var(req.path) path
124 http-request set-var(req.query) query
125 http-request set-var(req.param) url_param(qs_arg)
Willy Tarreauc48acd12023-08-09 11:02:34 +0200126 http-request set-var(req.cl) req.fhdr(content-length)
Willy Tarreau12989482018-12-07 18:21:21 +0100127
128 http-request set-header sl1 "sl1: "
129
130 http-request set-method "%[str(GET)]"
Christopher Faulet95d169b2020-01-17 23:21:59 +0100131 http-request set-uri %[str(),concat(/bu/,req.uri,/eu)]
Willy Tarreau12989482018-12-07 18:21:21 +0100132 http-request set-path "/bp/%[var(req.path)]/ep"
133 http-request set-query "bq&%[var(req.query)]&eq"
134
135 http-request set-header sl2 "sl2: "
136
137 http-request set-header sl1 "%[req.fhdr(sl1)] method=<%[var(req.method)]>; uri=<%[var(req.uri)]>; path=<%[var(req.path)]>;"
138 http-request set-header sl1 "%[req.fhdr(sl1)] query=<%[var(req.query)]>; param=<%[var(req.param)]>"
Willy Tarreauc48acd12023-08-09 11:02:34 +0200139 http-request set-header sl1 "%[req.fhdr(sl1)] cl=<%[var(req.cl)]>"
Willy Tarreau12989482018-12-07 18:21:21 +0100140 http-request set-header sl2 "%[req.fhdr(sl2)] method=<%[method]>; uri=<%[url]>; path=<%[path]>; "
141 http-request set-header sl2 "%[req.fhdr(sl2)] query=<%[query]>; param=<%[url_param(qs_arg)]>"
Willy Tarreauc48acd12023-08-09 11:02:34 +0200142 http-request set-header sl2 "%[req.fhdr(sl2)] cl=<%[req.fhdr(content-length)]>"
Willy Tarreau12989482018-12-07 18:21:21 +0100143 http-request set-header hdr "%[req.fhdr(hdr)] hdr1=<%[req.hdr(hdr1)]>; fhdr1=<%[req.fhdr(hdr1)]>;"
144 http-request set-header hdr "%[req.fhdr(hdr)] hdr2=<%[req.hdr(hdr2)]>; fhdr2=<%[req.fhdr(hdr2)]>;"
145 http-request set-header hdr "%[req.fhdr(hdr)] hdr3=<%[req.hdr(hdr3)]>; fhdr3=<%[req.fhdr(hdr3)]>;"
146 http-request set-header hdr "%[req.fhdr(hdr)] hdr4=<%[req.hdr(hdr4)]>; fhdr4=<%[req.fhdr(hdr4)]>;"
147
148 http-request set-header be-sl1-crc "%[req.fhdr(sl1),crc32]"
149 http-request set-header be-sl2-crc "%[req.fhdr(sl2),crc32]"
150 http-request set-header be-hdr-crc "%[req.fhdr(hdr),crc32]"
151
152 #### responses
153 http-response set-var(res.status) status
154 http-response set-header sl1 "sl1: "
155
156 http-response set-status 200
157
158 http-response set-header sl2 "sl2: "
159
160 http-response set-header sl1 "%[res.fhdr(sl1)] status=<%[var(res.status)]>;"
161 http-response set-header sl2 "%[res.fhdr(sl2)] status=<%[status]>;"
162 http-response set-header hdr "%[res.fhdr(hdr)] hdr1=<%[res.hdr(hdr1)]>; fhdr1=<%[res.fhdr(hdr1)]>;"
163 http-response set-header hdr "%[res.fhdr(hdr)] hdr2=<%[res.hdr(hdr2)]>; fhdr2=<%[res.fhdr(hdr2)]>;"
164 http-response set-header hdr "%[res.fhdr(hdr)] hdr3=<%[res.hdr(hdr3)]>; fhdr3=<%[res.fhdr(hdr3)]>;"
165 http-response set-header hdr "%[res.fhdr(hdr)] hdr4=<%[res.hdr(hdr4)]>; fhdr4=<%[res.fhdr(hdr4)]>;"
166
167 http-response set-header sl1-crc "%[res.fhdr(sl1),crc32]"
168 http-response set-header sl2-crc "%[res.fhdr(sl2),crc32]"
169 http-response set-header hdr-crc "%[res.fhdr(hdr),crc32]"
Christopher Fauletb4c4a972021-11-09 16:33:25 +0100170 http-response allow
171 http-response deny # must not be evaluated
Willy Tarreau12989482018-12-07 18:21:21 +0100172
173 server s1 ${s1_addr}:${s1_port}
174} -start
175
176client c1h1 -connect ${h1_feh1_sock} {
177 txreq \
178 -req GET \
179 -url /path/to/file.extension?qs_arg=qs_value \
Willy Tarreauc48acd12023-08-09 11:02:34 +0200180 -hdr "content-length: 000, 00" \
Willy Tarreau12989482018-12-07 18:21:21 +0100181 -hdr "hdr1: val1" \
182 -hdr "hdr2: val2a" \
183 -hdr "hdr2: val2b" \
184 -hdr "hdr3: val3a, val3b" \
185 -hdr "hdr4:"
186 rxresp
187
188 expect resp.status == 200
189 expect resp.http.be-sl1-crc == 487202719
190 expect resp.http.be-sl2-crc == 561949791
191 expect resp.http.be-hdr-crc == 1719311923
192 expect resp.http.fe-sl1-crc == 146151597
193 expect resp.http.fe-sl2-crc == 561949791
194 expect resp.http.fe-hdr-crc == 3634102538
195 expect resp.bodylen == 14
196 expect resp.body == "This is a body"
197} -run
198
199client c1h2 -connect ${h1_feh2_sock} {
Willy Tarreau211d5402018-12-13 17:29:20 +0100200 txpri
201 stream 0 {
202 txsettings
203 rxsettings
204 txsettings -ack
Willy Tarreau211d5402018-12-13 17:29:20 +0100205 rxsettings
206 expect settings.ack == true
207 } -run
Willy Tarreau12989482018-12-07 18:21:21 +0100208 stream 1 {
209 # warning: -req, -scheme, -url MUST be placed first otherwise
210 # the H2 protocol is invalid since they are pseudo-headers
211 txreq \
212 -req GET \
213 -scheme "https" \
214 -url /path/to/file.extension?qs_arg=qs_value \
Willy Tarreauc48acd12023-08-09 11:02:34 +0200215 -hdr "content-length" "000, 00" \
Willy Tarreau12989482018-12-07 18:21:21 +0100216 -hdr "hdr1" "val1" \
217 -hdr "hdr2" " val2a" \
218 -hdr "hdr2" " val2b" \
219 -hdr "hdr3" " val3a, val3b" \
220 -hdr "hdr4" ""
221
222 rxhdrs
223 expect resp.status == 200
224 expect resp.http.be-sl1-crc == 487202719
225 expect resp.http.be-sl2-crc == 561949791
226 expect resp.http.be-hdr-crc == 1719311923
227 expect resp.http.fe-sl1-crc == 146151597
228 expect resp.http.fe-sl2-crc == 561949791
229 expect resp.http.fe-hdr-crc == 3634102538
230 expect resp.http.content-length == 14
231
232 rxdata -all
233 expect resp.body == "This is a body"
234 } -run
235} -run