blob: 61d7af6710c1616db6e6a2af50c9718a230edcf4 [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
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100138 timeout connect 1s
139 timeout client 1s
140 timeout server 1s
141
142 frontend fe
143 bind "fd@${fe}"
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100144 use_backend no_vary_be if { path_beg /no_vary_support }
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100145 default_backend test
146
147 backend test
148 http-request cache-use my_cache
149 server www ${s1_addr}:${s1_port}
150 http-response cache-store my_cache
151 http-response set-header X-Cache-Hit %[res.cache_hit]
152
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100153 backend no_vary_be
154 http-request cache-use no_vary_cache
155 server www ${s2_addr}:${s2_port}
156 http-response cache-store no_vary_cache
157 http-response set-header X-Cache-Hit %[res.cache_hit]
158
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100159 cache my_cache
160 total-max-size 3
161 max-age 20
162 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100163 process-vary on
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100164
165 cache no_vary_cache
166 total-max-size 3
167 max-age 20
168 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100169 process-vary off
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100170} -start
171
172
173client c1 -connect ${h1_fe_sock} {
174 # Accept-Encoding Vary
175 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
176 rxresp
177 expect resp.status == 200
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100178 expect resp.http.content-encoding == "gzip"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100179 expect resp.bodylen == 45
180
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100181 # The response for the first request had an unacceptable `content-encoding`
182 # which might happen if that's the only thing the server supports, but
183 # we must not cache that and instead defer to the server.
184 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
185 rxresp
186 expect resp.status == 200
187 expect resp.http.content-encoding == "gzip"
188 expect resp.bodylen == 45
189 expect resp.http.X-Cache-Hit == 0
190
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100191 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
192 rxresp
193 expect resp.status == 200
194 expect resp.bodylen == 48
195 expect resp.http.content-type == "text/plain"
196 expect resp.http.X-Cache-Hit == 0
197
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100198 # This request matches the cache entry for the request above, despite
199 # matching the `accept-encoding` of the first request because the
200 # request above only has the `identity` encoding which is implicitly
Ilya Shipitsin1e9a6662021-01-05 22:10:46 +0500201 # added, unless explicitly forbidden.
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100202 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
203 rxresp
204 expect resp.status == 200
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100205 expect resp.bodylen == 48
206 expect resp.http.content-type == "text/plain"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100207 expect resp.http.X-Cache-Hit == 1
208
209 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
210 rxresp
211 expect resp.status == 200
212 expect resp.bodylen == 48
213 expect resp.http.content-type == "text/plain"
214 expect resp.http.X-Cache-Hit == 1
215
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100216 # The accept-encoding normalizer function converts the header values
217 # to lower case then calculates the hash of every sub part before
218 # sorting the hashes and xor'ing them (while removing duplicates).
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100219 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
220 rxresp
221 expect resp.status == 200
222 expect resp.bodylen == 51
223 expect resp.http.X-Cache-Hit == 0
224
225 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
226 rxresp
227 expect resp.status == 200
228 expect resp.bodylen == 51
229 expect resp.http.X-Cache-Hit == 1
230
231 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: second,first"
232 rxresp
233 expect resp.status == 200
234 expect resp.bodylen == 51
235 expect resp.http.X-Cache-Hit == 1
236
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100237 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: FirsT,SECOND,first"
238 rxresp
239 expect resp.status == 200
240 expect resp.bodylen == 51
241 expect resp.http.X-Cache-Hit == 1
242
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100243 # Unmanaged vary
244 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
245 rxresp
246 expect resp.status == 200
247 expect resp.bodylen == 51
248 expect resp.http.X-Cache-Hit == 0
249
250 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
251 rxresp
252 expect resp.status == 200
253 expect resp.bodylen == 51
254 expect resp.http.X-Cache-Hit == 0
255
256
257 # Mixed Vary (Accept-Encoding + Referer)
258 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100259 -hdr "Accept-Encoding: br, gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100260 -hdr "Referer: referer"
261 rxresp
262 expect resp.status == 200
263 expect resp.bodylen == 51
264 expect resp.http.X-Cache-Hit == 0
265
266 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100267 -hdr "Accept-Encoding: br" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100268 -hdr "Referer: other-referer"
269 rxresp
270 expect resp.status == 200
271 expect resp.bodylen == 54
272 expect resp.http.X-Cache-Hit == 0
273
274 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100275 -hdr "Accept-Encoding: gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100276 -hdr "Referer: other-referer"
277 rxresp
278 expect resp.status == 200
279 expect resp.bodylen == 57
280 expect resp.http.X-Cache-Hit == 0
281
282 txreq -url "/referer-accept-encoding" \
283 -hdr "Referer: referer" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100284 -hdr "Accept-Encoding: gzip, br"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100285 rxresp
286 expect resp.status == 200
287 expect resp.bodylen == 51
288 expect resp.http.X-Cache-Hit == 1
289
290 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100291 -hdr "Accept-Encoding: br" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100292 -hdr "Referer: other-referer"
293 rxresp
294 expect resp.status == 200
295 expect resp.bodylen == 54
296 expect resp.http.X-Cache-Hit == 1
297
298 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100299 -hdr "Accept-Encoding: gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100300 -hdr "Referer: other-referer"
301 rxresp
302 expect resp.status == 200
303 expect resp.bodylen == 57
304 expect resp.http.X-Cache-Hit == 1
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100305
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100306
307 # Multiple Accept-encoding headers
308 txreq -url "/multiple_headers" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100309 -hdr "Accept-Encoding: gzip" \
310 -hdr "Accept-Encoding: br, deflate"
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100311 rxresp
312 expect resp.status == 200
313 expect resp.bodylen == 155
314 expect resp.http.X-Cache-Hit == 0
315
316 txreq -url "/multiple_headers" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100317 -hdr "Accept-Encoding: deflate" \
318 -hdr "Accept-Encoding: br,gzip"
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100319 rxresp
320 expect resp.status == 200
321 expect resp.bodylen == 155
322 expect resp.http.X-Cache-Hit == 1
323
324 # Should not match a cache entry
325 txreq -url "/multiple_headers" \
326 -hdr "Accept-Encoding: first_encoding"
327 rxresp
328 expect resp.status == 200
329 expect resp.bodylen == 166
330 expect resp.http.X-Cache-Hit == 0
331
332 # Too many accept encodings
333 txreq -url "/too_many_encodings" \
334 -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
335 rxresp
336 expect resp.status == 200
337 expect resp.bodylen == 177
338 expect resp.http.X-Cache-Hit == 0
339
340 txreq -url "/too_many_encodings" \
341 -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
342 rxresp
343 expect resp.status == 200
344 expect resp.bodylen == 188
345 expect resp.http.X-Cache-Hit == 0
346
347
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100348 # The following requests are treated by a backend that does not cache
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100349 # responses containing a Vary header
350 txreq -url "/no_vary_support"
351 rxresp
352 expect resp.status == 200
353 expect resp.bodylen == 57
354 expect resp.http.X-Cache-Hit == 0
355
356 txreq -url "/no_vary_support"
357 rxresp
358 expect resp.status == 200
359 expect resp.bodylen == 57
360 expect resp.http.X-Cache-Hit == 0
361
362
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100363} -run