blob: 197f822b33a1b1bae498e4bb0567d28f19aa8a11 [file] [log] [blame]
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +01001varnishtest "Vary support"
2
Christopher Faulet85a81362020-12-15 17:13:39 +01003#REQUIRE_VERSION=2.4
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +01004
5feature ignore_unknown_macro
6
7server s1 {
Tim Duesterhusdc38bc42020-12-29 12:43:53 +01008 # Response varying on "accept-encoding" with
9 # an unacceptable content-encoding
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010010 rxreq
11 expect req.url == "/accept-encoding"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010012 txresp -hdr "Content-Encoding: gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010013 -hdr "Vary: accept-encoding" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010014 -hdr "Cache-Control: max-age=5" \
15 -bodylen 45
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010016
17 # Response varying on "accept-encoding"
18 rxreq
19 expect req.url == "/accept-encoding"
Tim Duesterhusdc38bc42020-12-29 12:43:53 +010020 txresp -hdr "Content-Encoding: gzip" \
21 -hdr "Vary: accept-encoding" \
22 -hdr "Cache-Control: max-age=5" \
23 -bodylen 45
24
25 # Response varying on "accept-encoding" with
26 # no content-encoding
27 rxreq
28 expect req.url == "/accept-encoding"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010029 txresp -hdr "Content-Type: text/plain" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010030 -hdr "Vary: accept-encoding" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010031 -hdr "Cache-Control: max-age=5" \
32 -bodylen 48
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010033
34 # Response varying on "accept-encoding" but having two different encodings
35 rxreq
36 expect req.url == "/accept-encoding-multiple"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010037 txresp -hdr "Vary: accept-encoding" \
38 -hdr "Cache-Control: max-age=5" \
39 -bodylen 51
40
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010041
42 # Unmanaged vary
43 rxreq
44 expect req.url == "/unmanaged"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010045 txresp -hdr "Vary: accept-encoding,unmanaged" \
46 -hdr "Cache-Control: max-age=5" \
47 -bodylen 51
48
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010049
50 rxreq
51 expect req.url == "/unmanaged"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010052 txresp -hdr "Vary: accept-encoding,unmanaged" \
53 -hdr "Cache-Control: max-age=5" \
54 -bodylen 51
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010055
56
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010057
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010058 # Mixed Vary (Accept-Encoding + Referer)
59 rxreq
60 expect req.url == "/referer-accept-encoding"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010061 txresp -hdr "Vary: accept-encoding,referer" \
62 -hdr "Cache-Control: max-age=5" \
63 -hdr "Content-Encoding: gzip" \
64 -bodylen 51
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010065
66 rxreq
67 expect req.url == "/referer-accept-encoding"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010068 txresp -hdr "Vary: referer,accept-encoding" \
69 -hdr "Cache-Control: max-age=5" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +010070 -hdr "Content-Encoding: br" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010071 -bodylen 54
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010072
73 rxreq
74 expect req.url == "/referer-accept-encoding"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010075 txresp -hdr "Vary: referer,accept-encoding" \
76 -hdr "Cache-Control: max-age=5" \
77 -hdr "Content-Encoding: gzip" \
78 -bodylen 57
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010079
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +010080 # Multiple Accept-Encoding headers
81 rxreq
82 expect req.url == "/multiple_headers"
83 txresp -hdr "Vary: accept-encoding" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010084 -hdr "Cache-Control: max-age=5" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +010085 -hdr "Content-Encoding: br" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010086 -bodylen 155
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +010087
88 rxreq
89 expect req.url == "/multiple_headers"
90 txresp -hdr "Vary: accept-encoding" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010091 -hdr "Cache-Control: max-age=5" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +010092 -hdr "Content-Encoding: br" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010093 -bodylen 166
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +010094
95
96 # Too many Accept-Encoding values (we will not cache responses with more than 16 encodings)
97 rxreq
98 expect req.url == "/too_many_encodings"
99 txresp -hdr "Vary: accept-encoding" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100100 -hdr "Cache-Control: max-age=5" \
101 -hdr "Content-Encoding: gzip" \
102 -bodylen 177
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100103
104 rxreq
105 expect req.url == "/too_many_encodings"
106 txresp -hdr "Vary: accept-encoding" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100107 -hdr "Cache-Control: max-age=5" \
108 -hdr "Content-Encoding: gzip" \
109 -bodylen 188
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100110
Tim Duesterhus3bc6af42021-06-18 15:09:28 +0200111 rxreq
112 expect req.url == "/empty-vs-missing"
113 txresp -hdr "Content-Encoding: gzip" \
114 -hdr "Vary: accept-encoding" \
115 -hdr "Cache-Control: max-age=5" \
116 -bodylen 234
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100117
Tim Duesterhus3bc6af42021-06-18 15:09:28 +0200118 rxreq
119 expect req.url == "/empty-vs-missing"
120 txresp -hdr "Vary: accept-encoding" \
121 -hdr "Cache-Control: max-age=5" \
122 -bodylen 256
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100123} -start
124
125server s2 {
126 # Responses that should not be cached
127 rxreq
128 expect req.url == "/no_vary_support"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100129 txresp -hdr "Vary: accept-encoding" \
130 -hdr "Cache-Control: max-age=5" \
131 -bodylen 57
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100132
133 rxreq
134 expect req.url == "/no_vary_support"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100135 txresp -hdr "Vary: accept-encoding" \
136 -hdr "Cache-Control: max-age=5" \
137 -bodylen 57
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100138} -start
139
140haproxy h1 -conf {
Willy Tarreaue1465c12021-05-09 14:41:41 +0200141 global
142 # WT: limit false-positives causing "HTTP header incomplete" due to
143 # idle server connections being randomly used and randomly expiring
144 # under us.
145 tune.idle-pool.shared off
146
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100147 defaults
148 mode http
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100149 timeout connect 1s
150 timeout client 1s
151 timeout server 1s
152
153 frontend fe
154 bind "fd@${fe}"
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100155 use_backend no_vary_be if { path_beg /no_vary_support }
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100156 default_backend test
157
158 backend test
159 http-request cache-use my_cache
160 server www ${s1_addr}:${s1_port}
161 http-response cache-store my_cache
162 http-response set-header X-Cache-Hit %[res.cache_hit]
163
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100164 backend no_vary_be
165 http-request cache-use no_vary_cache
166 server www ${s2_addr}:${s2_port}
167 http-response cache-store no_vary_cache
168 http-response set-header X-Cache-Hit %[res.cache_hit]
169
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100170 cache my_cache
171 total-max-size 3
172 max-age 20
173 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100174 process-vary on
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100175
176 cache no_vary_cache
177 total-max-size 3
178 max-age 20
179 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100180 process-vary off
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100181} -start
182
183
184client c1 -connect ${h1_fe_sock} {
185 # Accept-Encoding Vary
186 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
187 rxresp
188 expect resp.status == 200
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100189 expect resp.http.content-encoding == "gzip"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100190 expect resp.bodylen == 45
191
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100192 # The response for the first request had an unacceptable `content-encoding`
193 # which might happen if that's the only thing the server supports, but
194 # we must not cache that and instead defer to the server.
195 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
196 rxresp
197 expect resp.status == 200
198 expect resp.http.content-encoding == "gzip"
199 expect resp.bodylen == 45
200 expect resp.http.X-Cache-Hit == 0
201
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100202 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
203 rxresp
204 expect resp.status == 200
205 expect resp.bodylen == 48
206 expect resp.http.content-type == "text/plain"
207 expect resp.http.X-Cache-Hit == 0
208
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100209 # This request matches the cache entry for the request above, despite
210 # matching the `accept-encoding` of the first request because the
211 # request above only has the `identity` encoding which is implicitly
Ilya Shipitsin1e9a6662021-01-05 22:10:46 +0500212 # added, unless explicitly forbidden.
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100213 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
214 rxresp
215 expect resp.status == 200
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100216 expect resp.bodylen == 48
217 expect resp.http.content-type == "text/plain"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100218 expect resp.http.X-Cache-Hit == 1
219
220 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
221 rxresp
222 expect resp.status == 200
223 expect resp.bodylen == 48
224 expect resp.http.content-type == "text/plain"
225 expect resp.http.X-Cache-Hit == 1
226
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100227 # The accept-encoding normalizer function converts the header values
228 # to lower case then calculates the hash of every sub part before
229 # sorting the hashes and xor'ing them (while removing duplicates).
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100230 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
231 rxresp
232 expect resp.status == 200
233 expect resp.bodylen == 51
234 expect resp.http.X-Cache-Hit == 0
235
236 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
237 rxresp
238 expect resp.status == 200
239 expect resp.bodylen == 51
240 expect resp.http.X-Cache-Hit == 1
241
242 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: second,first"
243 rxresp
244 expect resp.status == 200
245 expect resp.bodylen == 51
246 expect resp.http.X-Cache-Hit == 1
247
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100248 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: FirsT,SECOND,first"
249 rxresp
250 expect resp.status == 200
251 expect resp.bodylen == 51
252 expect resp.http.X-Cache-Hit == 1
253
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100254 # Unmanaged vary
255 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
256 rxresp
257 expect resp.status == 200
258 expect resp.bodylen == 51
259 expect resp.http.X-Cache-Hit == 0
260
261 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
262 rxresp
263 expect resp.status == 200
264 expect resp.bodylen == 51
265 expect resp.http.X-Cache-Hit == 0
266
267
268 # Mixed Vary (Accept-Encoding + Referer)
269 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100270 -hdr "Accept-Encoding: br, gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100271 -hdr "Referer: referer"
272 rxresp
273 expect resp.status == 200
274 expect resp.bodylen == 51
275 expect resp.http.X-Cache-Hit == 0
276
277 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100278 -hdr "Accept-Encoding: br" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100279 -hdr "Referer: other-referer"
280 rxresp
281 expect resp.status == 200
282 expect resp.bodylen == 54
283 expect resp.http.X-Cache-Hit == 0
284
285 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100286 -hdr "Accept-Encoding: gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100287 -hdr "Referer: other-referer"
288 rxresp
289 expect resp.status == 200
290 expect resp.bodylen == 57
291 expect resp.http.X-Cache-Hit == 0
292
293 txreq -url "/referer-accept-encoding" \
294 -hdr "Referer: referer" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100295 -hdr "Accept-Encoding: gzip, br"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100296 rxresp
297 expect resp.status == 200
298 expect resp.bodylen == 51
299 expect resp.http.X-Cache-Hit == 1
300
301 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100302 -hdr "Accept-Encoding: br" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100303 -hdr "Referer: other-referer"
304 rxresp
305 expect resp.status == 200
306 expect resp.bodylen == 54
307 expect resp.http.X-Cache-Hit == 1
308
309 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100310 -hdr "Accept-Encoding: gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100311 -hdr "Referer: other-referer"
312 rxresp
313 expect resp.status == 200
314 expect resp.bodylen == 57
315 expect resp.http.X-Cache-Hit == 1
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100316
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100317
318 # Multiple Accept-encoding headers
319 txreq -url "/multiple_headers" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100320 -hdr "Accept-Encoding: gzip" \
321 -hdr "Accept-Encoding: br, deflate"
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100322 rxresp
323 expect resp.status == 200
324 expect resp.bodylen == 155
325 expect resp.http.X-Cache-Hit == 0
326
327 txreq -url "/multiple_headers" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100328 -hdr "Accept-Encoding: deflate" \
329 -hdr "Accept-Encoding: br,gzip"
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100330 rxresp
331 expect resp.status == 200
332 expect resp.bodylen == 155
333 expect resp.http.X-Cache-Hit == 1
334
335 # Should not match a cache entry
336 txreq -url "/multiple_headers" \
337 -hdr "Accept-Encoding: first_encoding"
338 rxresp
339 expect resp.status == 200
340 expect resp.bodylen == 166
341 expect resp.http.X-Cache-Hit == 0
342
343 # Too many accept encodings
344 txreq -url "/too_many_encodings" \
345 -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
346 rxresp
347 expect resp.status == 200
348 expect resp.bodylen == 177
349 expect resp.http.X-Cache-Hit == 0
350
351 txreq -url "/too_many_encodings" \
352 -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
353 rxresp
354 expect resp.status == 200
355 expect resp.bodylen == 188
356 expect resp.http.X-Cache-Hit == 0
357
Tim Duesterhus3bc6af42021-06-18 15:09:28 +0200358 # A missing 'Accept-Encoding' implies that anything is acceptable,
359 # while an empty 'Accept-Encoding' implies nothing is acceptable.
360
361 # Start by caching a gzip response.
362 txreq -url "/empty-vs-missing" -hdr "Accept-Encoding: gzip"
363 rxresp
364 expect resp.status == 200
365 expect resp.bodylen == 234
366 expect resp.http.content-encoding == "gzip"
367 expect resp.http.X-Cache-Hit == 0
368
369 # Check that it is cached.
370 txreq -url "/empty-vs-missing" -hdr "Accept-Encoding: gzip"
371 rxresp
372 expect resp.status == 200
373 expect resp.bodylen == 234
374 expect resp.http.content-encoding == "gzip"
375 expect resp.http.X-Cache-Hit == 1
376
377 # Check that the cached response is returned when no accept-encoding is
378 # specified.
379 txreq -url "/empty-vs-missing"
380 rxresp
381 expect resp.status == 200
382 expect resp.bodylen == 234
383 expect resp.http.content-encoding == "gzip"
384 expect resp.http.X-Cache-Hit == 1
385
386 # Check that the cached response is not returned when an empty
387 # accept-encoding is specified.
388 txreq -url "/empty-vs-missing" -hdr "Accept-Encoding:"
389 rxresp
390 expect resp.status == 200
391 expect resp.bodylen == 256
392 expect resp.http.content-encoding == "<undef>"
393 expect resp.http.X-Cache-Hit == 0
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100394
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100395 # The following requests are treated by a backend that does not cache
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100396 # responses containing a Vary header
397 txreq -url "/no_vary_support"
398 rxresp
399 expect resp.status == 200
400 expect resp.bodylen == 57
401 expect resp.http.X-Cache-Hit == 0
402
403 txreq -url "/no_vary_support"
404 rxresp
405 expect resp.status == 200
406 expect resp.bodylen == 57
407 expect resp.http.X-Cache-Hit == 0
408
409
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100410} -run