blob: ca86f1b909eddcc5d57d4374cda415d61cd25d9d [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"
30 expect req.http.fe-sl1-crc == 992395575
31 expect req.http.fe-sl2-crc == 1270056220
32 expect req.http.fe-hdr-crc == 1719311923
33 expect req.http.be-sl1-crc == 2604236007
34 expect req.http.be-sl2-crc == 4181358964
35 expect req.http.be-hdr-crc == 3634102538
36} -repeat 2 -start
37
38haproxy h1 -conf {
39 defaults
40 mode http
41 timeout connect 1s
42 timeout client 1s
43 timeout server 1s
44
45 frontend fe
46 bind "fd@${feh1}"
47 bind "fd@${feh2}" proto h2
48
49 #### requests
50 http-request set-var(req.method) method
51 http-request set-var(req.uri) url
52 http-request set-var(req.path) path
53 http-request set-var(req.query) query
54 http-request set-var(req.param) url_param(qs_arg)
55
56 http-request set-header sl1 "sl1: "
57
58 http-request set-method "%[str(GET)]"
59 http-request set-uri concat(/bu/,req.uri,/eu)
60 http-request set-path "/bp/%[var(req.path)]/ep"
61 http-request set-query "bq&%[var(req.query)]&eq"
62
63 http-request set-header sl2 "sl2: "
64
65 http-request set-header sl1 "%[req.fhdr(sl1)] method=<%[var(req.method)]>; uri=<%[var(req.uri)]>; path=<%[var(req.path)]>;"
66 http-request set-header sl1 "%[req.fhdr(sl1)] query=<%[var(req.query)]>; param=<%[var(req.param)]>"
67 http-request set-header sl2 "%[req.fhdr(sl2)] method=<%[method]>; uri=<%[url]>; path=<%[path]>; "
68 http-request set-header sl2 "%[req.fhdr(sl2)] query=<%[query]>; param=<%[url_param(qs_arg)]>"
69 http-request set-header hdr "%[req.fhdr(hdr)] hdr1=<%[req.hdr(hdr1)]>; fhdr1=<%[req.fhdr(hdr1)]>;"
70 http-request set-header hdr "%[req.fhdr(hdr)] hdr2=<%[req.hdr(hdr2)]>; fhdr2=<%[req.fhdr(hdr2)]>;"
71 http-request set-header hdr "%[req.fhdr(hdr)] hdr3=<%[req.hdr(hdr3)]>; fhdr3=<%[req.fhdr(hdr3)]>;"
72 http-request set-header hdr "%[req.fhdr(hdr)] hdr4=<%[req.hdr(hdr4)]>; fhdr4=<%[req.fhdr(hdr4)]>;"
73
74 http-request set-header sl1-crc "%[req.fhdr(sl1),crc32]"
75 http-request set-header sl2-crc "%[req.fhdr(sl2),crc32]"
76 http-request set-header hdr-crc "%[req.fhdr(hdr),crc32]"
77
78 #### responses
79 http-response set-header be-sl1 "%[res.fhdr(sl1)]"
80 http-response set-header be-sl2 "%[res.fhdr(sl2)]"
81 http-response set-header be-hdr "%[res.fhdr(hdr)]"
82
83 http-response set-header be-sl1-crc "%[res.fhdr(sl1-crc)]"
84 http-response set-header be-sl2-crc "%[res.fhdr(sl2-crc)]"
85 http-response set-header be-hdr-crc "%[res.fhdr(hdr-crc)]"
86
87 http-response set-var(res.status) status
88 http-response set-header sl1 "sl1: "
89
90 http-response set-status 200
91
92 http-response set-header sl2 "sl2: "
93
94 http-response set-header sl1 "%[res.fhdr(sl1)] status=<%[var(res.status)]>;"
95 http-response set-header sl2 "%[res.fhdr(sl2)] status=<%[status]>;"
96 http-response set-header hdr "%[res.fhdr(hdr)] hdr1=<%[res.hdr(hdr1)]>; fhdr1=<%[res.fhdr(hdr1)]>;"
97 http-response set-header hdr "%[res.fhdr(hdr)] hdr2=<%[res.hdr(hdr2)]>; fhdr2=<%[res.fhdr(hdr2)]>;"
98 http-response set-header hdr "%[res.fhdr(hdr)] hdr3=<%[res.hdr(hdr3)]>; fhdr3=<%[res.fhdr(hdr3)]>;"
99 http-response set-header hdr "%[res.fhdr(hdr)] hdr4=<%[res.hdr(hdr4)]>; fhdr4=<%[res.fhdr(hdr4)]>;"
100
101 http-response set-header fe-sl1-crc "%[res.fhdr(sl1),crc32]"
102 http-response set-header fe-sl2-crc "%[res.fhdr(sl2),crc32]"
103 http-response set-header fe-hdr-crc "%[res.fhdr(hdr),crc32]"
104
105 default_backend be
106
107 backend be
108 #### requests
109 http-request set-header fe-sl1 "%[req.fhdr(sl1)]"
110 http-request set-header fe-sl2 "%[req.fhdr(sl2)]"
111 http-request set-header fe-hdr "%[req.fhdr(hdr)]"
112
113 http-request set-header fe-sl1-crc "%[req.fhdr(sl1-crc)]"
114 http-request set-header fe-sl2-crc "%[req.fhdr(sl2-crc)]"
115 http-request set-header fe-hdr-crc "%[req.fhdr(hdr-crc)]"
116
117 http-request set-var(req.method) method
118 http-request set-var(req.uri) url
119 http-request set-var(req.path) path
120 http-request set-var(req.query) query
121 http-request set-var(req.param) url_param(qs_arg)
122
123 http-request set-header sl1 "sl1: "
124
125 http-request set-method "%[str(GET)]"
126 http-request set-uri concat(/bu/,req.uri,/eu)
127 http-request set-path "/bp/%[var(req.path)]/ep"
128 http-request set-query "bq&%[var(req.query)]&eq"
129
130 http-request set-header sl2 "sl2: "
131
132 http-request set-header sl1 "%[req.fhdr(sl1)] method=<%[var(req.method)]>; uri=<%[var(req.uri)]>; path=<%[var(req.path)]>;"
133 http-request set-header sl1 "%[req.fhdr(sl1)] query=<%[var(req.query)]>; param=<%[var(req.param)]>"
134 http-request set-header sl2 "%[req.fhdr(sl2)] method=<%[method]>; uri=<%[url]>; path=<%[path]>; "
135 http-request set-header sl2 "%[req.fhdr(sl2)] query=<%[query]>; param=<%[url_param(qs_arg)]>"
136 http-request set-header hdr "%[req.fhdr(hdr)] hdr1=<%[req.hdr(hdr1)]>; fhdr1=<%[req.fhdr(hdr1)]>;"
137 http-request set-header hdr "%[req.fhdr(hdr)] hdr2=<%[req.hdr(hdr2)]>; fhdr2=<%[req.fhdr(hdr2)]>;"
138 http-request set-header hdr "%[req.fhdr(hdr)] hdr3=<%[req.hdr(hdr3)]>; fhdr3=<%[req.fhdr(hdr3)]>;"
139 http-request set-header hdr "%[req.fhdr(hdr)] hdr4=<%[req.hdr(hdr4)]>; fhdr4=<%[req.fhdr(hdr4)]>;"
140
141 http-request set-header be-sl1-crc "%[req.fhdr(sl1),crc32]"
142 http-request set-header be-sl2-crc "%[req.fhdr(sl2),crc32]"
143 http-request set-header be-hdr-crc "%[req.fhdr(hdr),crc32]"
144
145 #### responses
146 http-response set-var(res.status) status
147 http-response set-header sl1 "sl1: "
148
149 http-response set-status 200
150
151 http-response set-header sl2 "sl2: "
152
153 http-response set-header sl1 "%[res.fhdr(sl1)] status=<%[var(res.status)]>;"
154 http-response set-header sl2 "%[res.fhdr(sl2)] status=<%[status]>;"
155 http-response set-header hdr "%[res.fhdr(hdr)] hdr1=<%[res.hdr(hdr1)]>; fhdr1=<%[res.fhdr(hdr1)]>;"
156 http-response set-header hdr "%[res.fhdr(hdr)] hdr2=<%[res.hdr(hdr2)]>; fhdr2=<%[res.fhdr(hdr2)]>;"
157 http-response set-header hdr "%[res.fhdr(hdr)] hdr3=<%[res.hdr(hdr3)]>; fhdr3=<%[res.fhdr(hdr3)]>;"
158 http-response set-header hdr "%[res.fhdr(hdr)] hdr4=<%[res.hdr(hdr4)]>; fhdr4=<%[res.fhdr(hdr4)]>;"
159
160 http-response set-header sl1-crc "%[res.fhdr(sl1),crc32]"
161 http-response set-header sl2-crc "%[res.fhdr(sl2),crc32]"
162 http-response set-header hdr-crc "%[res.fhdr(hdr),crc32]"
163
164 server s1 ${s1_addr}:${s1_port}
165} -start
166
167client c1h1 -connect ${h1_feh1_sock} {
168 txreq \
169 -req GET \
170 -url /path/to/file.extension?qs_arg=qs_value \
171 -hdr "hdr1: val1" \
172 -hdr "hdr2: val2a" \
173 -hdr "hdr2: val2b" \
174 -hdr "hdr3: val3a, val3b" \
175 -hdr "hdr4:"
176 rxresp
177
178 expect resp.status == 200
179 expect resp.http.be-sl1-crc == 487202719
180 expect resp.http.be-sl2-crc == 561949791
181 expect resp.http.be-hdr-crc == 1719311923
182 expect resp.http.fe-sl1-crc == 146151597
183 expect resp.http.fe-sl2-crc == 561949791
184 expect resp.http.fe-hdr-crc == 3634102538
185 expect resp.bodylen == 14
186 expect resp.body == "This is a body"
187} -run
188
189client c1h2 -connect ${h1_feh2_sock} {
190 stream 1 {
191 # warning: -req, -scheme, -url MUST be placed first otherwise
192 # the H2 protocol is invalid since they are pseudo-headers
193 txreq \
194 -req GET \
195 -scheme "https" \
196 -url /path/to/file.extension?qs_arg=qs_value \
197 -hdr "hdr1" "val1" \
198 -hdr "hdr2" " val2a" \
199 -hdr "hdr2" " val2b" \
200 -hdr "hdr3" " val3a, val3b" \
201 -hdr "hdr4" ""
202
203 rxhdrs
204 expect resp.status == 200
205 expect resp.http.be-sl1-crc == 487202719
206 expect resp.http.be-sl2-crc == 561949791
207 expect resp.http.be-hdr-crc == 1719311923
208 expect resp.http.fe-sl1-crc == 146151597
209 expect resp.http.fe-sl2-crc == 561949791
210 expect resp.http.fe-hdr-crc == 3634102538
211 expect resp.http.content-length == 14
212
213 rxdata -all
214 expect resp.body == "This is a body"
215 } -run
216} -run