blob: 0b5d139410fa61efc5637c7d86538e5e86c94932 [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
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100111
112} -start
113
114server s2 {
115 # Responses that should not be cached
116 rxreq
117 expect req.url == "/no_vary_support"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100118 txresp -hdr "Vary: accept-encoding" \
119 -hdr "Cache-Control: max-age=5" \
120 -bodylen 57
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100121
122 rxreq
123 expect req.url == "/no_vary_support"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100124 txresp -hdr "Vary: accept-encoding" \
125 -hdr "Cache-Control: max-age=5" \
126 -bodylen 57
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100127} -start
128
129haproxy h1 -conf {
Willy Tarreaue1465c12021-05-09 14:41:41 +0200130 global
131 # WT: limit false-positives causing "HTTP header incomplete" due to
132 # idle server connections being randomly used and randomly expiring
133 # under us.
134 tune.idle-pool.shared off
135
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100136 defaults
137 mode http
138 ${no-htx} option http-use-htx
139 timeout connect 1s
140 timeout client 1s
141 timeout server 1s
142
143 frontend fe
144 bind "fd@${fe}"
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100145 use_backend no_vary_be if { path_beg /no_vary_support }
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100146 default_backend test
147
148 backend test
149 http-request cache-use my_cache
150 server www ${s1_addr}:${s1_port}
151 http-response cache-store my_cache
152 http-response set-header X-Cache-Hit %[res.cache_hit]
153
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100154 backend no_vary_be
155 http-request cache-use no_vary_cache
156 server www ${s2_addr}:${s2_port}
157 http-response cache-store no_vary_cache
158 http-response set-header X-Cache-Hit %[res.cache_hit]
159
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100160 cache my_cache
161 total-max-size 3
162 max-age 20
163 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100164 process-vary on
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100165
166 cache no_vary_cache
167 total-max-size 3
168 max-age 20
169 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100170 process-vary off
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100171} -start
172
173
174client c1 -connect ${h1_fe_sock} {
175 # Accept-Encoding Vary
176 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
177 rxresp
178 expect resp.status == 200
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100179 expect resp.http.content-encoding == "gzip"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100180 expect resp.bodylen == 45
181
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100182 # The response for the first request had an unacceptable `content-encoding`
183 # which might happen if that's the only thing the server supports, but
184 # we must not cache that and instead defer to the server.
185 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
186 rxresp
187 expect resp.status == 200
188 expect resp.http.content-encoding == "gzip"
189 expect resp.bodylen == 45
190 expect resp.http.X-Cache-Hit == 0
191
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100192 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
193 rxresp
194 expect resp.status == 200
195 expect resp.bodylen == 48
196 expect resp.http.content-type == "text/plain"
197 expect resp.http.X-Cache-Hit == 0
198
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100199 # This request matches the cache entry for the request above, despite
200 # matching the `accept-encoding` of the first request because the
201 # request above only has the `identity` encoding which is implicitly
Ilya Shipitsin1e9a6662021-01-05 22:10:46 +0500202 # added, unless explicitly forbidden.
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100203 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
204 rxresp
205 expect resp.status == 200
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100206 expect resp.bodylen == 48
207 expect resp.http.content-type == "text/plain"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100208 expect resp.http.X-Cache-Hit == 1
209
210 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
211 rxresp
212 expect resp.status == 200
213 expect resp.bodylen == 48
214 expect resp.http.content-type == "text/plain"
215 expect resp.http.X-Cache-Hit == 1
216
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100217 # The accept-encoding normalizer function converts the header values
218 # to lower case then calculates the hash of every sub part before
219 # sorting the hashes and xor'ing them (while removing duplicates).
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100220 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
221 rxresp
222 expect resp.status == 200
223 expect resp.bodylen == 51
224 expect resp.http.X-Cache-Hit == 0
225
226 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
227 rxresp
228 expect resp.status == 200
229 expect resp.bodylen == 51
230 expect resp.http.X-Cache-Hit == 1
231
232 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: second,first"
233 rxresp
234 expect resp.status == 200
235 expect resp.bodylen == 51
236 expect resp.http.X-Cache-Hit == 1
237
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100238 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: FirsT,SECOND,first"
239 rxresp
240 expect resp.status == 200
241 expect resp.bodylen == 51
242 expect resp.http.X-Cache-Hit == 1
243
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100244 # Unmanaged vary
245 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
246 rxresp
247 expect resp.status == 200
248 expect resp.bodylen == 51
249 expect resp.http.X-Cache-Hit == 0
250
251 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
252 rxresp
253 expect resp.status == 200
254 expect resp.bodylen == 51
255 expect resp.http.X-Cache-Hit == 0
256
257
258 # Mixed Vary (Accept-Encoding + Referer)
259 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100260 -hdr "Accept-Encoding: br, gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100261 -hdr "Referer: referer"
262 rxresp
263 expect resp.status == 200
264 expect resp.bodylen == 51
265 expect resp.http.X-Cache-Hit == 0
266
267 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100268 -hdr "Accept-Encoding: br" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100269 -hdr "Referer: other-referer"
270 rxresp
271 expect resp.status == 200
272 expect resp.bodylen == 54
273 expect resp.http.X-Cache-Hit == 0
274
275 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100276 -hdr "Accept-Encoding: gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100277 -hdr "Referer: other-referer"
278 rxresp
279 expect resp.status == 200
280 expect resp.bodylen == 57
281 expect resp.http.X-Cache-Hit == 0
282
283 txreq -url "/referer-accept-encoding" \
284 -hdr "Referer: referer" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100285 -hdr "Accept-Encoding: gzip, br"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100286 rxresp
287 expect resp.status == 200
288 expect resp.bodylen == 51
289 expect resp.http.X-Cache-Hit == 1
290
291 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100292 -hdr "Accept-Encoding: br" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100293 -hdr "Referer: other-referer"
294 rxresp
295 expect resp.status == 200
296 expect resp.bodylen == 54
297 expect resp.http.X-Cache-Hit == 1
298
299 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100300 -hdr "Accept-Encoding: gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100301 -hdr "Referer: other-referer"
302 rxresp
303 expect resp.status == 200
304 expect resp.bodylen == 57
305 expect resp.http.X-Cache-Hit == 1
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100306
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100307
308 # Multiple Accept-encoding headers
309 txreq -url "/multiple_headers" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100310 -hdr "Accept-Encoding: gzip" \
311 -hdr "Accept-Encoding: br, deflate"
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100312 rxresp
313 expect resp.status == 200
314 expect resp.bodylen == 155
315 expect resp.http.X-Cache-Hit == 0
316
317 txreq -url "/multiple_headers" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100318 -hdr "Accept-Encoding: deflate" \
319 -hdr "Accept-Encoding: br,gzip"
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100320 rxresp
321 expect resp.status == 200
322 expect resp.bodylen == 155
323 expect resp.http.X-Cache-Hit == 1
324
325 # Should not match a cache entry
326 txreq -url "/multiple_headers" \
327 -hdr "Accept-Encoding: first_encoding"
328 rxresp
329 expect resp.status == 200
330 expect resp.bodylen == 166
331 expect resp.http.X-Cache-Hit == 0
332
333 # Too many accept encodings
334 txreq -url "/too_many_encodings" \
335 -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
336 rxresp
337 expect resp.status == 200
338 expect resp.bodylen == 177
339 expect resp.http.X-Cache-Hit == 0
340
341 txreq -url "/too_many_encodings" \
342 -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
343 rxresp
344 expect resp.status == 200
345 expect resp.bodylen == 188
346 expect resp.http.X-Cache-Hit == 0
347
348
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100349 # The following requests are treated by a backend that does not cache
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100350 # responses containing a Vary header
351 txreq -url "/no_vary_support"
352 rxresp
353 expect resp.status == 200
354 expect resp.bodylen == 57
355 expect resp.http.X-Cache-Hit == 0
356
357 txreq -url "/no_vary_support"
358 rxresp
359 expect resp.status == 200
360 expect resp.bodylen == 57
361 expect resp.http.X-Cache-Hit == 0
362
363
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100364} -run