blob: 185ad0502bf003dd2d006f5f975de01425f35216 [file] [log] [blame]
Remi Tricot-Le Breton14df1e12020-12-23 18:13:51 +01001varnishtest "Check the Accept-Encoding processing implemented in the Vary mechanism"
2
3#REQUIRE_VERSION=2.4
4
5feature ignore_unknown_macro
6
7server s1 {
8 # Response varying on "accept-encoding" with a gzip content-encoding
9 rxreq
10 expect req.url == "/accept-encoding"
11 txresp -hdr "Content-Encoding: gzip" \
12 -hdr "Vary: accept-encoding" \
13 -hdr "Cache-Control: max-age=5" \
14 -bodylen 45
15
16 # Response varying on "accept-encoding" with a deflate content-encoding
17 rxreq
18 expect req.url == "/accept-encoding"
19 txresp -hdr "Content-Encoding: deflate" \
20 -hdr "Vary: accept-encoding" \
21 -hdr "Cache-Control: max-age=5" \
22 -bodylen 55
23
24
25 # Response varying on "accept-encoding" with no content-encoding (identity)
26 rxreq
27 expect req.url == "/accept-encoding-identity"
28 txresp -hdr "Vary: accept-encoding" \
29 -hdr "Cache-Control: max-age=5" \
30 -bodylen 65
31
32 # Response varying on "accept-encoding" with refused identity encoding
33 rxreq
34 expect req.url == "/accept-encoding-identity"
35 txresp -hdr "Vary: accept-encoding" \
36 -hdr "Cache-Control: max-age=5" \
37 -hdr "Content-Encoding: deflate" \
38 -bodylen 75
39
40
41 rxreq
42 expect req.url == "/accept-encoding-star"
43 txresp -hdr "Vary: accept-encoding" \
44 -hdr "Cache-Control: max-age=5" \
45 -hdr "Content-Encoding: br" \
46 -bodylen 89
47
48 rxreq
49 expect req.url == "/accept-encoding-star"
50 txresp -hdr "Vary: accept-encoding" \
51 -hdr "Cache-Control: max-age=5" \
52 -hdr "Content-Encoding: deflate" \
53 -bodylen 99
54
55
56 rxreq
57 expect req.url == "/multiple-content-encoding"
58 txresp -hdr "Vary: accept-encoding" \
59 -hdr "Cache-Control: max-age=5" \
60 -hdr "Content-Encoding: deflate, gzip" \
61 -bodylen 109
62
63 rxreq
64 expect req.url == "/unknown-content-encoding"
65 txresp -hdr "Vary: accept-encoding" \
66 -hdr "Cache-Control: max-age=5" \
67 -hdr "Content-Encoding: unknown_encoding" \
68 -bodylen 119
69
70 rxreq
71 expect req.url == "/unknown-content-encoding"
72 txresp -hdr "Vary: accept-encoding" \
73 -hdr "Cache-Control: max-age=5" \
74 -hdr "Content-Encoding: unknown_encoding" \
75 -bodylen 119
Tim Duesterhusdc38bc42020-12-29 12:43:53 +010076
77
78 rxreq
79 expect req.url == "/hash-collision"
80 txresp -hdr "Vary: accept-encoding" \
81 -hdr "Cache-Control: max-age=5" \
82 -hdr "Content-Encoding: br" \
83 -bodylen 129
84
85 rxreq
86 expect req.url == "/hash-collision"
87 txresp -hdr "Vary: accept-encoding" \
88 -hdr "Cache-Control: max-age=5" \
89 -hdr "Content-Encoding: gzip" \
90 -bodylen 139
Remi Tricot-Le Breton14df1e12020-12-23 18:13:51 +010091} -start
92
93
94haproxy h1 -conf {
95 defaults
96 mode http
97 ${no-htx} option http-use-htx
98 timeout connect 1s
99 timeout client 1s
100 timeout server 1s
101
102 frontend fe
103 bind "fd@${fe}"
104 default_backend test
105
106 backend test
107 http-request cache-use my_cache
108 server www ${s1_addr}:${s1_port}
109 http-response cache-store my_cache
110 http-response set-header X-Cache-Hit %[res.cache_hit]
111
112 cache my_cache
113 total-max-size 3
114 max-age 20
115 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100116 process-vary on
Remi Tricot-Le Breton14df1e12020-12-23 18:13:51 +0100117} -start
118
119
120client c1 -connect ${h1_fe_sock} {
121 #
122 # Accept-Encoding Vary
123 #
124
125 # First request
126 txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip"
127 rxresp
128 expect resp.status == 200
129 expect resp.http.content-encoding == "gzip"
130 expect resp.bodylen == 45
131
132 # Regular case
133 txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip"
134 rxresp
135 expect resp.status == 200
136 expect resp.http.content-encoding == "gzip"
137 expect resp.bodylen == 45
138 expect resp.http.X-Cache-Hit == 1
139
140 # Regular case with upper case encoding
141 txreq -url "/accept-encoding" -hdr "Accept-Encoding: GZIP"
142 rxresp
143 expect resp.status == 200
144 expect resp.http.content-encoding == "gzip"
145 expect resp.bodylen == 45
146 expect resp.http.X-Cache-Hit == 1
147
148 # Multiple accepted encodings (all standard)
149 txreq -url "/accept-encoding" -hdr "Accept-Encoding: deflate,gzip"
150 rxresp
151 expect resp.status == 200
152 expect resp.http.content-encoding == "gzip"
153 expect resp.bodylen == 45
154 expect resp.http.X-Cache-Hit == 1
155
156 # Multiple accept-encoding headers + non-standard accepted encodings
157 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_encoding,second_encoding" -hdr "Accept-Encoding: gzip"
158 rxresp
159 expect resp.status == 200
160 expect resp.http.content-encoding == "gzip"
161 expect resp.bodylen == 45
162 expect resp.http.X-Cache-Hit == 1
163
164 # Regular case with positive weight
165 txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip;q=0.8"
166 rxresp
167 expect resp.status == 200
168 expect resp.http.content-encoding == "gzip"
169 expect resp.bodylen == 45
170 expect resp.http.X-Cache-Hit == 1
171
172 # Regular case with positive weight and extra whitespaces
173 txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip ; q=0.8"
174 rxresp
175 expect resp.status == 200
176 expect resp.http.content-encoding == "gzip"
177 expect resp.bodylen == 45
178 expect resp.http.X-Cache-Hit == 1
179
180 # Regular case with null weight
181 txreq -url "/accept-encoding" -hdr "Accept-Encoding: deflate;q=0.8, gzip;q=0"
182 rxresp
183 expect resp.status == 200
184 expect resp.http.content-encoding == "deflate"
185 expect resp.bodylen == 55
186 expect resp.http.X-Cache-Hit == 0
187
188
189 #
190 # Identity tests
191 #
192 txreq -url "/accept-encoding-identity"
193 rxresp
194 expect resp.status == 200
195 expect resp.http.content-encoding == "<undef>"
196 expect resp.bodylen == 65
197 expect resp.http.X-Cache-Hit == 0
198
199 # Regular case
200 txreq -url "/accept-encoding-identity"
201 rxresp
202 expect resp.status == 200
203 expect resp.http.content-encoding == "<undef>"
204 expect resp.bodylen == 65
205 expect resp.http.X-Cache-Hit == 1
206
207 # Identity is allowed by default even if another encoding is specified
208 txreq -url "/accept-encoding-identity" -hdr "Accept-Encoding: gzip"
209 rxresp
210 expect resp.status == 200
211 expect resp.http.content-encoding == "<undef>"
212 expect resp.bodylen == 65
213 expect resp.http.X-Cache-Hit == 1
214
215 # Refused identity encoding (explicit null weight)
216 txreq -url "/accept-encoding-identity" -hdr "Accept-Encoding: deflate, identity;q=0"
217 rxresp
218 expect resp.status == 200
219 expect resp.http.content-encoding == "deflate"
220 expect resp.bodylen == 75
221 expect resp.http.X-Cache-Hit == 0
222
223
224 #
225 # Star tests
226 #
227 txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: *"
228 rxresp
229 expect resp.status == 200
230 expect resp.http.content-encoding == "br"
231 expect resp.bodylen == 89
232 expect resp.http.X-Cache-Hit == 0
233
234 # Regular case
235 txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: *"
236 rxresp
237 expect resp.status == 200
238 expect resp.http.content-encoding == "br"
239 expect resp.bodylen == 89
240 expect resp.http.X-Cache-Hit == 1
241
242 # Reject some encodings
243 txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*"
244 rxresp
245 expect resp.status == 200
246 expect resp.http.content-encoding == "br"
247 expect resp.bodylen == 89
248 expect resp.http.X-Cache-Hit == 1
249
250 # Weighted star
251 txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*;q=0.1"
252 rxresp
253 expect resp.status == 200
254 expect resp.http.content-encoding == "br"
255 expect resp.bodylen == 89
256 expect resp.http.X-Cache-Hit == 1
257
258 # Rejected identity
259 txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*;q=0.1,identity;q=0"
260 rxresp
261 expect resp.status == 200
262 expect resp.http.content-encoding == "br"
263 expect resp.bodylen == 89
264 expect resp.http.X-Cache-Hit == 1
265
266 # Rejected star and "br" not accepted
267 txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*;q=0"
268 rxresp
269 expect resp.status == 200
270 expect resp.http.content-encoding == "deflate"
271 expect resp.bodylen == 99
272 expect resp.http.X-Cache-Hit == 0
273
274
275 #
276 # Multiple content-encodings
277 #
278 txreq -url "/multiple-content-encoding" -hdr "Accept-Encoding: gzip;q=0.8, deflate"
279 rxresp
280 expect resp.status == 200
281 expect resp.http.content-encoding == "deflate, gzip"
282 expect resp.bodylen == 109
283 expect resp.http.X-Cache-Hit == 0
284
285 txreq -url "/multiple-content-encoding" -hdr "Accept-Encoding: deflate,gzip;q=0.7"
286 rxresp
287 expect resp.status == 200
288 expect resp.http.content-encoding == "deflate, gzip"
289 expect resp.bodylen == 109
290 expect resp.http.X-Cache-Hit == 1
291
292
293 #
294 # Unknown content-encoding
Remi Tricot-Le Breton6ca89162021-01-07 14:50:51 +0100295 # The response should not be cached since it has an unknown content encoding
Remi Tricot-Le Breton14df1e12020-12-23 18:13:51 +0100296 #
297 txreq -url "/unknown-content-encoding" -hdr "Accept-Encoding: gzip;q=0.8, deflate, first_encoding"
298 rxresp
299 expect resp.status == 200
300 expect resp.http.content-encoding == "unknown_encoding"
301 expect resp.bodylen == 119
302 expect resp.http.X-Cache-Hit == 0
303
304 txreq -url "/unknown-content-encoding" -hdr "Accept-Encoding: deflate,gzip;q=0.8, first_encoding"
305 rxresp
306 expect resp.status == 200
307 expect resp.http.content-encoding == "unknown_encoding"
308 expect resp.bodylen == 119
Remi Tricot-Le Breton14df1e12020-12-23 18:13:51 +0100309 expect resp.http.X-Cache-Hit == 0
310
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100311 #
312 # Hash collision (https://github.com/haproxy/haproxy/issues/988)
313 #
314 # crc32(gzip) ^ crc32(br) ^ crc32(xxx) ^ crc32(jdcqiab) == crc32(gzip)
315 txreq -url "/hash-collision" -hdr "Accept-Encoding: br,gzip,xxx,jdcqiab"
316 rxresp
317 expect resp.status == 200
318 expect resp.http.content-encoding == "br"
319 expect resp.bodylen == 129
320 expect resp.http.X-Cache-Hit == 0
321
322 txreq -url "/hash-collision" -hdr "Accept-Encoding: gzip"
323 rxresp
324 expect resp.status == 200
325 expect resp.http.content-encoding == "gzip"
326 expect resp.bodylen == 139
327 expect resp.http.X-Cache-Hit == 0
Remi Tricot-Le Breton14df1e12020-12-23 18:13:51 +0100328} -run