blob: a840799f3829947253e9bb1c5ba55ae1b9e5e788 [file] [log] [blame]
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +01001varnishtest "Vary support"
2
3#REQUIRE_VERSION=2.3
4
5feature ignore_unknown_macro
6
7server s1 {
8 # Response varying on "accept-encoding"
9 rxreq
10 expect req.url == "/accept-encoding"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010011 txresp -hdr "Content-Encoding: gzip" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010012 -hdr "Vary: accept-encoding" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010013 -hdr "Cache-Control: max-age=5" \
14 -bodylen 45
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010015
16 # Response varying on "accept-encoding"
17 rxreq
18 expect req.url == "/accept-encoding"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010019 txresp -hdr "Content-Type: text/plain" \
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010020 -hdr "Vary: accept-encoding" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010021 -hdr "Cache-Control: max-age=5" \
22 -bodylen 48
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010023
24 # Response varying on "accept-encoding" but having two different encodings
25 rxreq
26 expect req.url == "/accept-encoding-multiple"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010027 txresp -hdr "Vary: accept-encoding" \
28 -hdr "Cache-Control: max-age=5" \
29 -bodylen 51
30
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010031
32 # Unmanaged vary
33 rxreq
34 expect req.url == "/unmanaged"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010035 txresp -hdr "Vary: accept-encoding,unmanaged" \
36 -hdr "Cache-Control: max-age=5" \
37 -bodylen 51
38
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010039
40 rxreq
41 expect req.url == "/unmanaged"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010042 txresp -hdr "Vary: accept-encoding,unmanaged" \
43 -hdr "Cache-Control: max-age=5" \
44 -bodylen 51
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010045
46
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010047
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010048 # Mixed Vary (Accept-Encoding + Referer)
49 rxreq
50 expect req.url == "/referer-accept-encoding"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010051 txresp -hdr "Vary: accept-encoding,referer" \
52 -hdr "Cache-Control: max-age=5" \
53 -hdr "Content-Encoding: gzip" \
54 -bodylen 51
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010055
56 rxreq
57 expect req.url == "/referer-accept-encoding"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010058 txresp -hdr "Vary: referer,accept-encoding" \
59 -hdr "Cache-Control: max-age=5" \
60 -hdr "Content-Encoding: gzip" \
61 -bodylen 54
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010062
63 rxreq
64 expect req.url == "/referer-accept-encoding"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010065 txresp -hdr "Vary: referer,accept-encoding" \
66 -hdr "Cache-Control: max-age=5" \
67 -hdr "Content-Encoding: gzip" \
68 -bodylen 57
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +010069
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +010070 # Multiple Accept-Encoding headers
71 rxreq
72 expect req.url == "/multiple_headers"
73 txresp -hdr "Vary: accept-encoding" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010074 -hdr "Cache-Control: max-age=5" \
75 -hdr "Content-Encoding: gzip" \
76 -bodylen 155
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +010077
78 rxreq
79 expect req.url == "/multiple_headers"
80 txresp -hdr "Vary: accept-encoding" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010081 -hdr "Cache-Control: max-age=5" \
82 -hdr "Content-Encoding: gzip" \
83 -bodylen 166
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +010084
85
86 # Too many Accept-Encoding values (we will not cache responses with more than 16 encodings)
87 rxreq
88 expect req.url == "/too_many_encodings"
89 txresp -hdr "Vary: accept-encoding" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010090 -hdr "Cache-Control: max-age=5" \
91 -hdr "Content-Encoding: gzip" \
92 -bodylen 177
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +010093
94 rxreq
95 expect req.url == "/too_many_encodings"
96 txresp -hdr "Vary: accept-encoding" \
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +010097 -hdr "Cache-Control: max-age=5" \
98 -hdr "Content-Encoding: gzip" \
99 -bodylen 188
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100100
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100101
102} -start
103
104server s2 {
105 # Responses that should not be cached
106 rxreq
107 expect req.url == "/no_vary_support"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100108 txresp -hdr "Vary: accept-encoding" \
109 -hdr "Cache-Control: max-age=5" \
110 -bodylen 57
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100111
112 rxreq
113 expect req.url == "/no_vary_support"
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100114 txresp -hdr "Vary: accept-encoding" \
115 -hdr "Cache-Control: max-age=5" \
116 -bodylen 57
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100117} -start
118
119haproxy h1 -conf {
120 defaults
121 mode http
122 ${no-htx} option http-use-htx
123 timeout connect 1s
124 timeout client 1s
125 timeout server 1s
126
127 frontend fe
128 bind "fd@${fe}"
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100129 use_backend no_vary_be if { path_beg /no_vary_support }
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100130 default_backend test
131
132 backend test
133 http-request cache-use my_cache
134 server www ${s1_addr}:${s1_port}
135 http-response cache-store my_cache
136 http-response set-header X-Cache-Hit %[res.cache_hit]
137
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100138 backend no_vary_be
139 http-request cache-use no_vary_cache
140 server www ${s2_addr}:${s2_port}
141 http-response cache-store no_vary_cache
142 http-response set-header X-Cache-Hit %[res.cache_hit]
143
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100144 cache my_cache
145 total-max-size 3
146 max-age 20
147 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100148 process-vary on
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100149
150 cache no_vary_cache
151 total-max-size 3
152 max-age 20
153 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100154 process-vary off
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100155} -start
156
157
158client c1 -connect ${h1_fe_sock} {
159 # Accept-Encoding Vary
160 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
161 rxresp
162 expect resp.status == 200
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100163 expect resp.http.content-encoding == "gzip"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100164 expect resp.bodylen == 45
165
166 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
167 rxresp
168 expect resp.status == 200
169 expect resp.bodylen == 48
170 expect resp.http.content-type == "text/plain"
171 expect resp.http.X-Cache-Hit == 0
172
173 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
174 rxresp
175 expect resp.status == 200
176 expect resp.bodylen == 45
Remi Tricot-Le Bretonb054b6d2020-12-23 18:13:50 +0100177 expect resp.http.content-encoding == "gzip"
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100178 expect resp.http.X-Cache-Hit == 1
179
180 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
181 rxresp
182 expect resp.status == 200
183 expect resp.bodylen == 48
184 expect resp.http.content-type == "text/plain"
185 expect resp.http.X-Cache-Hit == 1
186
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100187 # The accept-encoding normalizer function converts the header values
188 # to lower case then calculates the hash of every sub part before
189 # sorting the hashes and xor'ing them (while removing duplicates).
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100190 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
191 rxresp
192 expect resp.status == 200
193 expect resp.bodylen == 51
194 expect resp.http.X-Cache-Hit == 0
195
196 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
197 rxresp
198 expect resp.status == 200
199 expect resp.bodylen == 51
200 expect resp.http.X-Cache-Hit == 1
201
202 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: second,first"
203 rxresp
204 expect resp.status == 200
205 expect resp.bodylen == 51
206 expect resp.http.X-Cache-Hit == 1
207
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100208 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: FirsT,SECOND,first"
209 rxresp
210 expect resp.status == 200
211 expect resp.bodylen == 51
212 expect resp.http.X-Cache-Hit == 1
213
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100214 # Unmanaged vary
215 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
216 rxresp
217 expect resp.status == 200
218 expect resp.bodylen == 51
219 expect resp.http.X-Cache-Hit == 0
220
221 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
222 rxresp
223 expect resp.status == 200
224 expect resp.bodylen == 51
225 expect resp.http.X-Cache-Hit == 0
226
227
228 # Mixed Vary (Accept-Encoding + Referer)
229 txreq -url "/referer-accept-encoding" \
230 -hdr "Accept-Encoding: first_value,second_value" \
231 -hdr "Referer: referer"
232 rxresp
233 expect resp.status == 200
234 expect resp.bodylen == 51
235 expect resp.http.X-Cache-Hit == 0
236
237 txreq -url "/referer-accept-encoding" \
238 -hdr "Accept-Encoding: first_value" \
239 -hdr "Referer: other-referer"
240 rxresp
241 expect resp.status == 200
242 expect resp.bodylen == 54
243 expect resp.http.X-Cache-Hit == 0
244
245 txreq -url "/referer-accept-encoding" \
246 -hdr "Accept-Encoding: second_value" \
247 -hdr "Referer: other-referer"
248 rxresp
249 expect resp.status == 200
250 expect resp.bodylen == 57
251 expect resp.http.X-Cache-Hit == 0
252
253 txreq -url "/referer-accept-encoding" \
254 -hdr "Referer: referer" \
255 -hdr "Accept-Encoding: second_value,first_value"
256 rxresp
257 expect resp.status == 200
258 expect resp.bodylen == 51
259 expect resp.http.X-Cache-Hit == 1
260
261 txreq -url "/referer-accept-encoding" \
262 -hdr "Accept-Encoding: first_value" \
263 -hdr "Referer: other-referer"
264 rxresp
265 expect resp.status == 200
266 expect resp.bodylen == 54
267 expect resp.http.X-Cache-Hit == 1
268
269 txreq -url "/referer-accept-encoding" \
270 -hdr "Accept-Encoding: second_value" \
271 -hdr "Referer: other-referer"
272 rxresp
273 expect resp.status == 200
274 expect resp.bodylen == 57
275 expect resp.http.X-Cache-Hit == 1
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100276
Remi Tricot-Le Bretone4421de2020-12-23 18:13:46 +0100277
278 # Multiple Accept-encoding headers
279 txreq -url "/multiple_headers" \
280 -hdr "Accept-Encoding: first_encoding" \
281 -hdr "Accept-Encoding: second_encoding,third_encoding"
282 rxresp
283 expect resp.status == 200
284 expect resp.bodylen == 155
285 expect resp.http.X-Cache-Hit == 0
286
287 txreq -url "/multiple_headers" \
288 -hdr "Accept-Encoding: third_encoding" \
289 -hdr "Accept-Encoding: second_encoding,first_encoding"
290 rxresp
291 expect resp.status == 200
292 expect resp.bodylen == 155
293 expect resp.http.X-Cache-Hit == 1
294
295 # Should not match a cache entry
296 txreq -url "/multiple_headers" \
297 -hdr "Accept-Encoding: first_encoding"
298 rxresp
299 expect resp.status == 200
300 expect resp.bodylen == 166
301 expect resp.http.X-Cache-Hit == 0
302
303 # Too many accept encodings
304 txreq -url "/too_many_encodings" \
305 -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
306 rxresp
307 expect resp.status == 200
308 expect resp.bodylen == 177
309 expect resp.http.X-Cache-Hit == 0
310
311 txreq -url "/too_many_encodings" \
312 -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
313 rxresp
314 expect resp.status == 200
315 expect resp.bodylen == 188
316 expect resp.http.X-Cache-Hit == 0
317
318
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100319 # The following requests are treated by a backend that does not cache
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100320 # responses containing a Vary header
321 txreq -url "/no_vary_support"
322 rxresp
323 expect resp.status == 200
324 expect resp.bodylen == 57
325 expect resp.http.X-Cache-Hit == 0
326
327 txreq -url "/no_vary_support"
328 rxresp
329 expect resp.status == 200
330 expect resp.bodylen == 57
331 expect resp.http.X-Cache-Hit == 0
332
333
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100334} -run