blob: f3425d00212521cee3c53029648cdc1381809b9c [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 {
130 defaults
131 mode http
132 ${no-htx} option http-use-htx
133 timeout connect 1s
134 timeout client 1s
135 timeout server 1s
136
137 frontend fe
138 bind "fd@${fe}"
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100139 use_backend no_vary_be if { path_beg /no_vary_support }
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100140 default_backend test
141
142 backend test
143 http-request cache-use my_cache
144 server www ${s1_addr}:${s1_port}
145 http-response cache-store my_cache
146 http-response set-header X-Cache-Hit %[res.cache_hit]
147
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100148 backend no_vary_be
149 http-request cache-use no_vary_cache
150 server www ${s2_addr}:${s2_port}
151 http-response cache-store no_vary_cache
152 http-response set-header X-Cache-Hit %[res.cache_hit]
153
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100154 cache my_cache
155 total-max-size 3
156 max-age 20
157 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100158 process-vary on
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100159
160 cache no_vary_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 off
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100165} -start
166
167
168client c1 -connect ${h1_fe_sock} {
169 # Accept-Encoding Vary
170 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
171 rxresp
172 expect resp.status == 200
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100173 expect resp.http.content-encoding == "gzip"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100174 expect resp.bodylen == 45
175
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100176 # The response for the first request had an unacceptable `content-encoding`
177 # which might happen if that's the only thing the server supports, but
178 # we must not cache that and instead defer to the server.
179 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
180 rxresp
181 expect resp.status == 200
182 expect resp.http.content-encoding == "gzip"
183 expect resp.bodylen == 45
184 expect resp.http.X-Cache-Hit == 0
185
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100186 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
187 rxresp
188 expect resp.status == 200
189 expect resp.bodylen == 48
190 expect resp.http.content-type == "text/plain"
191 expect resp.http.X-Cache-Hit == 0
192
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100193 # This request matches the cache entry for the request above, despite
194 # matching the `accept-encoding` of the first request because the
195 # request above only has the `identity` encoding which is implicitly
Ilya Shipitsin1e9a6662021-01-05 22:10:46 +0500196 # added, unless explicitly forbidden.
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100197 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
198 rxresp
199 expect resp.status == 200
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100200 expect resp.bodylen == 48
201 expect resp.http.content-type == "text/plain"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100202 expect resp.http.X-Cache-Hit == 1
203
204 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
205 rxresp
206 expect resp.status == 200
207 expect resp.bodylen == 48
208 expect resp.http.content-type == "text/plain"
209 expect resp.http.X-Cache-Hit == 1
210
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100211 # The accept-encoding normalizer function converts the header values
212 # to lower case then calculates the hash of every sub part before
213 # sorting the hashes and xor'ing them (while removing duplicates).
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100214 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
215 rxresp
216 expect resp.status == 200
217 expect resp.bodylen == 51
218 expect resp.http.X-Cache-Hit == 0
219
220 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 == 1
225
226 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: second,first"
227 rxresp
228 expect resp.status == 200
229 expect resp.bodylen == 51
230 expect resp.http.X-Cache-Hit == 1
231
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100232 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: FirsT,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 Breton1785f3d2020-11-16 15:56:09 +0100238 # Unmanaged vary
239 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
240 rxresp
241 expect resp.status == 200
242 expect resp.bodylen == 51
243 expect resp.http.X-Cache-Hit == 0
244
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
252 # Mixed Vary (Accept-Encoding + Referer)
253 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100254 -hdr "Accept-Encoding: br, gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100255 -hdr "Referer: referer"
256 rxresp
257 expect resp.status == 200
258 expect resp.bodylen == 51
259 expect resp.http.X-Cache-Hit == 0
260
261 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100262 -hdr "Accept-Encoding: br" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100263 -hdr "Referer: other-referer"
264 rxresp
265 expect resp.status == 200
266 expect resp.bodylen == 54
267 expect resp.http.X-Cache-Hit == 0
268
269 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100270 -hdr "Accept-Encoding: gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100271 -hdr "Referer: other-referer"
272 rxresp
273 expect resp.status == 200
274 expect resp.bodylen == 57
275 expect resp.http.X-Cache-Hit == 0
276
277 txreq -url "/referer-accept-encoding" \
278 -hdr "Referer: referer" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100279 -hdr "Accept-Encoding: gzip, br"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100280 rxresp
281 expect resp.status == 200
282 expect resp.bodylen == 51
283 expect resp.http.X-Cache-Hit == 1
284
285 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100286 -hdr "Accept-Encoding: br" \
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 == 54
291 expect resp.http.X-Cache-Hit == 1
292
293 txreq -url "/referer-accept-encoding" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100294 -hdr "Accept-Encoding: gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100295 -hdr "Referer: other-referer"
296 rxresp
297 expect resp.status == 200
298 expect resp.bodylen == 57
299 expect resp.http.X-Cache-Hit == 1
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100300
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100301
302 # Multiple Accept-encoding headers
303 txreq -url "/multiple_headers" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100304 -hdr "Accept-Encoding: gzip" \
305 -hdr "Accept-Encoding: br, deflate"
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100306 rxresp
307 expect resp.status == 200
308 expect resp.bodylen == 155
309 expect resp.http.X-Cache-Hit == 0
310
311 txreq -url "/multiple_headers" \
Tim Duesterhusdc38bc42020-12-29 12:43:53 +0100312 -hdr "Accept-Encoding: deflate" \
313 -hdr "Accept-Encoding: br,gzip"
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100314 rxresp
315 expect resp.status == 200
316 expect resp.bodylen == 155
317 expect resp.http.X-Cache-Hit == 1
318
319 # Should not match a cache entry
320 txreq -url "/multiple_headers" \
321 -hdr "Accept-Encoding: first_encoding"
322 rxresp
323 expect resp.status == 200
324 expect resp.bodylen == 166
325 expect resp.http.X-Cache-Hit == 0
326
327 # Too many accept encodings
328 txreq -url "/too_many_encodings" \
329 -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
330 rxresp
331 expect resp.status == 200
332 expect resp.bodylen == 177
333 expect resp.http.X-Cache-Hit == 0
334
335 txreq -url "/too_many_encodings" \
336 -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
337 rxresp
338 expect resp.status == 200
339 expect resp.bodylen == 188
340 expect resp.http.X-Cache-Hit == 0
341
342
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100343 # The following requests are treated by a backend that does not cache
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100344 # responses containing a Vary header
345 txreq -url "/no_vary_support"
346 rxresp
347 expect resp.status == 200
348 expect resp.bodylen == 57
349 expect resp.http.X-Cache-Hit == 0
350
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
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100358} -run