blob: 25388f8a8130c3e267ffa4acf1902b3cfd81d316 [file] [log] [blame]
Willy Tarreau12989482018-12-07 18:21:21 +01001varnishtest "Composite HTTP manipulation test (H1 clear to H1 clear)"
Willy Tarreau4d58ba72018-12-07 15:18:54 +01002#REQUIRE_VERSION=1.6
Willy Tarreau12989482018-12-07 18:21:21 +01003#REQUIRE_VERSION_BELOW=1.9
Willy Tarreau4d58ba72018-12-07 15:18:54 +01004
5# This config tests several http-request features and their interactions.
6# It extracts some samples, places them into variables, modifies some header
7# fields, appends multiple identical header fields, overwrites the start line
8# using several methods, then dumps the initial list of variables and the final
9# one, then applies CRC32 to these values as signatures that are easy to test.
10# Then it does it again in the backend after saving the current headers into
11# the same names prefixed by "fe-". Then it does the same on the response path.
12# If some modifications are performed, the crc values need to be adjusted based
13# on the failed logs.
14#
15# Run it with HAPROXY_PROGRAM=$PWD/haproxy varnishtest -l -k -t 1 "$1"
16
17feature ignore_unknown_macro
18
19server s1 {
20 rxreq
21 txresp \
22 -status 234 \
23 -hdr "hdr1: val1" \
24 -hdr "hdr2: val2a" \
25 -hdr "hdr2: val2b" \
26 -hdr "hdr3: val3a, val3b" \
27 -hdr "hdr4:" \
28 -bodylen 14 \
29 -body "This is a body"
30
31 expect req.method == "GET"
32 expect req.http.fe-sl1-crc == 992395575
33 expect req.http.fe-sl2-crc == 1270056220
34 expect req.http.fe-hdr-crc == 1719311923
35 expect req.http.be-sl1-crc == 2604236007
36 expect req.http.be-sl2-crc == 4181358964
37 expect req.http.be-hdr-crc == 3634102538
38} -start
39
40haproxy h1 -conf {
41 defaults
42 mode http
43 timeout connect 1s
44 timeout client 1s
45 timeout server 1s
46
47 frontend fe
48 bind "fd@${fe}"
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)
56
57 http-request set-header sl1 "sl1: "
58
59 http-request set-method "%[str(GET)]"
60 http-request set-uri concat(/bu/,req.uri,/eu)
61 http-request set-path "/bp/%[var(req.path)]/ep"
62 http-request set-query "bq&%[var(req.query)]&eq"
63
64 http-request set-header sl2 "sl2: "
65
66 http-request set-header sl1 "%[req.fhdr(sl1)] method=<%[var(req.method)]>; uri=<%[var(req.uri)]>; path=<%[var(req.path)]>;"
67 http-request set-header sl1 "%[req.fhdr(sl1)] query=<%[var(req.query)]>; param=<%[var(req.param)]>"
68 http-request set-header sl2 "%[req.fhdr(sl2)] method=<%[method]>; uri=<%[url]>; path=<%[path]>; "
69 http-request set-header sl2 "%[req.fhdr(sl2)] query=<%[query]>; param=<%[url_param(qs_arg)]>"
70 http-request set-header hdr "%[req.fhdr(hdr)] hdr1=<%[req.hdr(hdr1)]>; fhdr1=<%[req.fhdr(hdr1)]>;"
71 http-request set-header hdr "%[req.fhdr(hdr)] hdr2=<%[req.hdr(hdr2)]>; fhdr2=<%[req.fhdr(hdr2)]>;"
72 http-request set-header hdr "%[req.fhdr(hdr)] hdr3=<%[req.hdr(hdr3)]>; fhdr3=<%[req.fhdr(hdr3)]>;"
73 http-request set-header hdr "%[req.fhdr(hdr)] hdr4=<%[req.hdr(hdr4)]>; fhdr4=<%[req.fhdr(hdr4)]>;"
74
75 http-request set-header sl1-crc "%[req.fhdr(sl1),crc32]"
76 http-request set-header sl2-crc "%[req.fhdr(sl2),crc32]"
77 http-request set-header hdr-crc "%[req.fhdr(hdr),crc32]"
78
79 #### responses
80 http-response set-header be-sl1 "%[res.fhdr(sl1)]"
81 http-response set-header be-sl2 "%[res.fhdr(sl2)]"
82 http-response set-header be-hdr "%[res.fhdr(hdr)]"
83
84 http-response set-header be-sl1-crc "%[res.fhdr(sl1-crc)]"
85 http-response set-header be-sl2-crc "%[res.fhdr(sl2-crc)]"
86 http-response set-header be-hdr-crc "%[res.fhdr(hdr-crc)]"
87
88 http-response set-var(res.status) status
89 http-response set-header sl1 "sl1: "
90
91 http-response set-status 200
92
93 http-response set-header sl2 "sl2: "
94
95 http-response set-header sl1 "%[res.fhdr(sl1)] status=<%[var(res.status)]>;"
96 http-response set-header sl2 "%[res.fhdr(sl2)] status=<%[status]>;"
97 http-response set-header hdr "%[res.fhdr(hdr)] hdr1=<%[res.hdr(hdr1)]>; fhdr1=<%[res.fhdr(hdr1)]>;"
98 http-response set-header hdr "%[res.fhdr(hdr)] hdr2=<%[res.hdr(hdr2)]>; fhdr2=<%[res.fhdr(hdr2)]>;"
99 http-response set-header hdr "%[res.fhdr(hdr)] hdr3=<%[res.hdr(hdr3)]>; fhdr3=<%[res.fhdr(hdr3)]>;"
100 http-response set-header hdr "%[res.fhdr(hdr)] hdr4=<%[res.hdr(hdr4)]>; fhdr4=<%[res.fhdr(hdr4)]>;"
101
102 http-response set-header fe-sl1-crc "%[res.fhdr(sl1),crc32]"
103 http-response set-header fe-sl2-crc "%[res.fhdr(sl2),crc32]"
104 http-response set-header fe-hdr-crc "%[res.fhdr(hdr),crc32]"
105
106 default_backend be
107
108 backend be
109 #### requests
110 http-request set-header fe-sl1 "%[req.fhdr(sl1)]"
111 http-request set-header fe-sl2 "%[req.fhdr(sl2)]"
112 http-request set-header fe-hdr "%[req.fhdr(hdr)]"
113
114 http-request set-header fe-sl1-crc "%[req.fhdr(sl1-crc)]"
115 http-request set-header fe-sl2-crc "%[req.fhdr(sl2-crc)]"
116 http-request set-header fe-hdr-crc "%[req.fhdr(hdr-crc)]"
117
118 http-request set-var(req.method) method
119 http-request set-var(req.uri) url
120 http-request set-var(req.path) path
121 http-request set-var(req.query) query
122 http-request set-var(req.param) url_param(qs_arg)
123
124 http-request set-header sl1 "sl1: "
125
126 http-request set-method "%[str(GET)]"
127 http-request set-uri concat(/bu/,req.uri,/eu)
128 http-request set-path "/bp/%[var(req.path)]/ep"
129 http-request set-query "bq&%[var(req.query)]&eq"
130
131 http-request set-header sl2 "sl2: "
132
133 http-request set-header sl1 "%[req.fhdr(sl1)] method=<%[var(req.method)]>; uri=<%[var(req.uri)]>; path=<%[var(req.path)]>;"
134 http-request set-header sl1 "%[req.fhdr(sl1)] query=<%[var(req.query)]>; param=<%[var(req.param)]>"
135 http-request set-header sl2 "%[req.fhdr(sl2)] method=<%[method]>; uri=<%[url]>; path=<%[path]>; "
136 http-request set-header sl2 "%[req.fhdr(sl2)] query=<%[query]>; param=<%[url_param(qs_arg)]>"
137 http-request set-header hdr "%[req.fhdr(hdr)] hdr1=<%[req.hdr(hdr1)]>; fhdr1=<%[req.fhdr(hdr1)]>;"
138 http-request set-header hdr "%[req.fhdr(hdr)] hdr2=<%[req.hdr(hdr2)]>; fhdr2=<%[req.fhdr(hdr2)]>;"
139 http-request set-header hdr "%[req.fhdr(hdr)] hdr3=<%[req.hdr(hdr3)]>; fhdr3=<%[req.fhdr(hdr3)]>;"
140 http-request set-header hdr "%[req.fhdr(hdr)] hdr4=<%[req.hdr(hdr4)]>; fhdr4=<%[req.fhdr(hdr4)]>;"
141
142 http-request set-header be-sl1-crc "%[req.fhdr(sl1),crc32]"
143 http-request set-header be-sl2-crc "%[req.fhdr(sl2),crc32]"
144 http-request set-header be-hdr-crc "%[req.fhdr(hdr),crc32]"
145
146 #### responses
147 http-response set-var(res.status) status
148 http-response set-header sl1 "sl1: "
149
150 http-response set-status 200
151
152 http-response set-header sl2 "sl2: "
153
154 http-response set-header sl1 "%[res.fhdr(sl1)] status=<%[var(res.status)]>;"
155 http-response set-header sl2 "%[res.fhdr(sl2)] status=<%[status]>;"
156 http-response set-header hdr "%[res.fhdr(hdr)] hdr1=<%[res.hdr(hdr1)]>; fhdr1=<%[res.fhdr(hdr1)]>;"
157 http-response set-header hdr "%[res.fhdr(hdr)] hdr2=<%[res.hdr(hdr2)]>; fhdr2=<%[res.fhdr(hdr2)]>;"
158 http-response set-header hdr "%[res.fhdr(hdr)] hdr3=<%[res.hdr(hdr3)]>; fhdr3=<%[res.fhdr(hdr3)]>;"
159 http-response set-header hdr "%[res.fhdr(hdr)] hdr4=<%[res.hdr(hdr4)]>; fhdr4=<%[res.fhdr(hdr4)]>;"
160
161 http-response set-header sl1-crc "%[res.fhdr(sl1),crc32]"
162 http-response set-header sl2-crc "%[res.fhdr(sl2),crc32]"
163 http-response set-header hdr-crc "%[res.fhdr(hdr),crc32]"
164
165 server s1 ${s1_addr}:${s1_port}
166} -start
167
168client c1 -connect ${h1_fe_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