blob: 512ff3ac37aa8a757a811f7d7c51f30b7abeb656 [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 Duesterhusbeec7ea2021-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 Duesterhusbeec7ea2021-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
149 ${no-htx} option http-use-htx
150 timeout connect 1s
151 timeout client 1s
152 timeout server 1s
153
154 frontend fe
155 bind "fd@${fe}"
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100156 use_backend no_vary_be if { path_beg /no_vary_support }
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100157 default_backend test
158
159 backend test
160 http-request cache-use my_cache
161 server www ${s1_addr}:${s1_port}
162 http-response cache-store my_cache
163 http-response set-header X-Cache-Hit %[res.cache_hit]
164
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100165 backend no_vary_be
166 http-request cache-use no_vary_cache
167 server www ${s2_addr}:${s2_port}
168 http-response cache-store no_vary_cache
169 http-response set-header X-Cache-Hit %[res.cache_hit]
170
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100171 cache my_cache
172 total-max-size 3
173 max-age 20
174 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100175 process-vary on
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100176
177 cache no_vary_cache
178 total-max-size 3
179 max-age 20
180 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100181 process-vary off
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100182} -start
183
184
185client c1 -connect ${h1_fe_sock} {
186 # Accept-Encoding Vary
187 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
188 rxresp
189 expect resp.status == 200
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100190 expect resp.http.content-encoding == "gzip"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100191 expect resp.bodylen == 45
192
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100193 # The response for the first request had an unacceptable `content-encoding`
194 # which might happen if that's the only thing the server supports, but
195 # we must not cache that and instead defer to the server.
196 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
197 rxresp
198 expect resp.status == 200
199 expect resp.http.content-encoding == "gzip"
200 expect resp.bodylen == 45
201 expect resp.http.X-Cache-Hit == 0
202
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100203 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
204 rxresp
205 expect resp.status == 200
206 expect resp.bodylen == 48
207 expect resp.http.content-type == "text/plain"
208 expect resp.http.X-Cache-Hit == 0
209
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100210 # This request matches the cache entry for the request above, despite
211 # matching the `accept-encoding` of the first request because the
212 # request above only has the `identity` encoding which is implicitly
Ilya Shipitsin1e9a6662021-01-05 22:10:46 +0500213 # added, unless explicitly forbidden.
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100214 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
215 rxresp
216 expect resp.status == 200
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100217 expect resp.bodylen == 48
218 expect resp.http.content-type == "text/plain"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100219 expect resp.http.X-Cache-Hit == 1
220
221 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
222 rxresp
223 expect resp.status == 200
224 expect resp.bodylen == 48
225 expect resp.http.content-type == "text/plain"
226 expect resp.http.X-Cache-Hit == 1
227
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100228 # The accept-encoding normalizer function converts the header values
229 # to lower case then calculates the hash of every sub part before
230 # sorting the hashes and xor'ing them (while removing duplicates).
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100231 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
232 rxresp
233 expect resp.status == 200
234 expect resp.bodylen == 51
235 expect resp.http.X-Cache-Hit == 0
236
237 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
238 rxresp
239 expect resp.status == 200
240 expect resp.bodylen == 51
241 expect resp.http.X-Cache-Hit == 1
242
243 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: second,first"
244 rxresp
245 expect resp.status == 200
246 expect resp.bodylen == 51
247 expect resp.http.X-Cache-Hit == 1
248
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100249 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: FirsT,SECOND,first"
250 rxresp
251 expect resp.status == 200
252 expect resp.bodylen == 51
253 expect resp.http.X-Cache-Hit == 1
254
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100255 # Unmanaged vary
256 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
257 rxresp
258 expect resp.status == 200
259 expect resp.bodylen == 51
260 expect resp.http.X-Cache-Hit == 0
261
262 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
263 rxresp
264 expect resp.status == 200
265 expect resp.bodylen == 51
266 expect resp.http.X-Cache-Hit == 0
267
268
269 # Mixed Vary (Accept-Encoding + Referer)
270 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100271 -hdr "Accept-Encoding: br, gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100272 -hdr "Referer: referer"
273 rxresp
274 expect resp.status == 200
275 expect resp.bodylen == 51
276 expect resp.http.X-Cache-Hit == 0
277
278 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100279 -hdr "Accept-Encoding: br" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100280 -hdr "Referer: other-referer"
281 rxresp
282 expect resp.status == 200
283 expect resp.bodylen == 54
284 expect resp.http.X-Cache-Hit == 0
285
286 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100287 -hdr "Accept-Encoding: gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100288 -hdr "Referer: other-referer"
289 rxresp
290 expect resp.status == 200
291 expect resp.bodylen == 57
292 expect resp.http.X-Cache-Hit == 0
293
294 txreq -url "/referer-accept-encoding" \
295 -hdr "Referer: referer" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100296 -hdr "Accept-Encoding: gzip, br"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100297 rxresp
298 expect resp.status == 200
299 expect resp.bodylen == 51
300 expect resp.http.X-Cache-Hit == 1
301
302 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100303 -hdr "Accept-Encoding: br" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100304 -hdr "Referer: other-referer"
305 rxresp
306 expect resp.status == 200
307 expect resp.bodylen == 54
308 expect resp.http.X-Cache-Hit == 1
309
310 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100311 -hdr "Accept-Encoding: gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100312 -hdr "Referer: other-referer"
313 rxresp
314 expect resp.status == 200
315 expect resp.bodylen == 57
316 expect resp.http.X-Cache-Hit == 1
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100317
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100318
319 # Multiple Accept-encoding headers
320 txreq -url "/multiple_headers" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100321 -hdr "Accept-Encoding: gzip" \
322 -hdr "Accept-Encoding: br, deflate"
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100323 rxresp
324 expect resp.status == 200
325 expect resp.bodylen == 155
326 expect resp.http.X-Cache-Hit == 0
327
328 txreq -url "/multiple_headers" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100329 -hdr "Accept-Encoding: deflate" \
330 -hdr "Accept-Encoding: br,gzip"
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100331 rxresp
332 expect resp.status == 200
333 expect resp.bodylen == 155
334 expect resp.http.X-Cache-Hit == 1
335
336 # Should not match a cache entry
337 txreq -url "/multiple_headers" \
338 -hdr "Accept-Encoding: first_encoding"
339 rxresp
340 expect resp.status == 200
341 expect resp.bodylen == 166
342 expect resp.http.X-Cache-Hit == 0
343
344 # Too many accept encodings
345 txreq -url "/too_many_encodings" \
346 -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
347 rxresp
348 expect resp.status == 200
349 expect resp.bodylen == 177
350 expect resp.http.X-Cache-Hit == 0
351
352 txreq -url "/too_many_encodings" \
353 -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
354 rxresp
355 expect resp.status == 200
356 expect resp.bodylen == 188
357 expect resp.http.X-Cache-Hit == 0
358
Tim Duesterhusbeec7ea2021-06-18 15:09:28 +0200359 # A missing 'Accept-Encoding' implies that anything is acceptable,
360 # while an empty 'Accept-Encoding' implies nothing is acceptable.
361
362 # Start by caching a gzip response.
363 txreq -url "/empty-vs-missing" -hdr "Accept-Encoding: gzip"
364 rxresp
365 expect resp.status == 200
366 expect resp.bodylen == 234
367 expect resp.http.content-encoding == "gzip"
368 expect resp.http.X-Cache-Hit == 0
369
370 # Check that it is cached.
371 txreq -url "/empty-vs-missing" -hdr "Accept-Encoding: gzip"
372 rxresp
373 expect resp.status == 200
374 expect resp.bodylen == 234
375 expect resp.http.content-encoding == "gzip"
376 expect resp.http.X-Cache-Hit == 1
377
378 # Check that the cached response is returned when no accept-encoding is
379 # specified.
380 txreq -url "/empty-vs-missing"
381 rxresp
382 expect resp.status == 200
383 expect resp.bodylen == 234
384 expect resp.http.content-encoding == "gzip"
385 expect resp.http.X-Cache-Hit == 1
386
387 # Check that the cached response is not returned when an empty
388 # accept-encoding is specified.
389 txreq -url "/empty-vs-missing" -hdr "Accept-Encoding:"
390 rxresp
391 expect resp.status == 200
392 expect resp.bodylen == 256
393 expect resp.http.content-encoding == "<undef>"
394 expect resp.http.X-Cache-Hit == 0
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100395
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100396 # The following requests are treated by a backend that does not cache
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100397 # responses containing a Vary header
398 txreq -url "/no_vary_support"
399 rxresp
400 expect resp.status == 200
401 expect resp.bodylen == 57
402 expect resp.http.X-Cache-Hit == 0
403
404 txreq -url "/no_vary_support"
405 rxresp
406 expect resp.status == 200
407 expect resp.bodylen == 57
408 expect resp.http.X-Cache-Hit == 0
409
410
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100411} -run