summaryrefslogtreecommitdiffstats
path: root/reg-tests/cache/vary.vtc
blob: 6c8cedf337aa21827d72fcd630a10828e8dccd29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
varnishtest "Vary support"

#REQUIRE_VERSION=2.4

feature ignore_unknown_macro

server s1 {
       # Response varying on "accept-encoding" with
       # an unacceptable content-encoding
       rxreq
       expect req.url == "/accept-encoding"
       txresp -hdr "Content-Encoding: gzip" \
               -hdr "Vary: accept-encoding" \
               -hdr "Cache-Control: max-age=5" \
               -bodylen 45

       # Response varying on "accept-encoding"
       rxreq
       expect req.url == "/accept-encoding"
       txresp -hdr "Content-Encoding: gzip" \
               -hdr "Vary: accept-encoding" \
               -hdr "Cache-Control: max-age=5" \
               -bodylen 45

       # Response varying on "accept-encoding" with
       # no content-encoding
       rxreq
       expect req.url == "/accept-encoding"
       txresp -hdr "Content-Type: text/plain" \
               -hdr "Vary: accept-encoding" \
               -hdr "Cache-Control: max-age=5" \
               -bodylen 48

       # Response varying on "accept-encoding" but having two different encodings
       rxreq
       expect req.url == "/accept-encoding-multiple"
       txresp -hdr "Vary: accept-encoding" \
               -hdr "Cache-Control: max-age=5" \
               -bodylen 51


       # Unmanaged vary
       rxreq
       expect req.url == "/unmanaged"
       txresp -hdr "Vary: accept-encoding,unmanaged" \
               -hdr "Cache-Control: max-age=5" \
               -bodylen 51


       rxreq
       expect req.url == "/unmanaged"
       txresp -hdr "Vary: accept-encoding,unmanaged" \
               -hdr "Cache-Control: max-age=5" \
               -bodylen 51



       # Mixed Vary (Accept-Encoding + Referer)
       rxreq
       expect req.url == "/referer-accept-encoding"
       txresp -hdr "Vary: accept-encoding,referer" \
               -hdr "Cache-Control: max-age=5" \
               -hdr "Content-Encoding: gzip" \
               -bodylen 51

       rxreq
       expect req.url == "/referer-accept-encoding"
       txresp -hdr "Vary: referer,accept-encoding" \
               -hdr "Cache-Control: max-age=5" \
               -hdr "Content-Encoding: br" \
               -bodylen 54

       rxreq
       expect req.url == "/referer-accept-encoding"
       txresp -hdr "Vary: referer,accept-encoding" \
               -hdr "Cache-Control: max-age=5" \
               -hdr "Content-Encoding: gzip" \
               -bodylen 57

       rxreq
       expect req.url == "/origin-referer-accept-encoding"
       txresp -hdr "Vary: origin,referer,accept-encoding" \
              -hdr "Cache-Control: max-age=5" \
              -hdr "Content-Encoding: gzip" \
              -bodylen 58

       rxreq
       expect req.url == "/origin-referer-accept-encoding"
       txresp -hdr "Vary: origin,referer,accept-encoding" \
              -hdr "Cache-Control: max-age=5" \
              -hdr "Content-Encoding: gzip" \
              -bodylen 59

       # Multiple Accept-Encoding headers
       rxreq
       expect req.url == "/multiple_headers"
       txresp -hdr "Vary: accept-encoding" \
              -hdr "Cache-Control: max-age=5" \
               -hdr "Content-Encoding: br" \
              -bodylen 155

       rxreq
       expect req.url == "/multiple_headers"
       txresp -hdr "Vary: accept-encoding" \
              -hdr "Cache-Control: max-age=5" \
               -hdr "Content-Encoding: br" \
              -bodylen 166


       # Too many Accept-Encoding values (we will not cache responses with more than 16 encodings)
       rxreq
       expect req.url == "/too_many_encodings"
       txresp -hdr "Vary: accept-encoding" \
              -hdr "Cache-Control: max-age=5" \
               -hdr "Content-Encoding: gzip" \
              -bodylen 177

       rxreq
       expect req.url == "/too_many_encodings"
       txresp -hdr "Vary: accept-encoding" \
              -hdr "Cache-Control: max-age=5" \
               -hdr "Content-Encoding: gzip" \
              -bodylen 188

       rxreq
       expect req.url == "/empty-vs-missing"
       txresp -hdr "Content-Encoding: gzip" \
               -hdr "Vary: accept-encoding" \
               -hdr "Cache-Control: max-age=5" \
               -bodylen 234

       rxreq
       expect req.url == "/empty-vs-missing"
       txresp -hdr "Vary: accept-encoding" \
               -hdr "Cache-Control: max-age=5" \
               -bodylen 256
} -start

server s2 {
       # Responses that should not be cached
       rxreq
       expect req.url == "/no_vary_support"
       txresp -hdr "Vary: accept-encoding" \
               -hdr "Cache-Control: max-age=5" \
               -bodylen 57

       rxreq
       expect req.url == "/no_vary_support"
       txresp -hdr "Vary: accept-encoding" \
               -hdr "Cache-Control: max-age=5" \
               -bodylen 57
} -start

haproxy h1 -conf {
       global
               # WT: limit false-positives causing "HTTP header incomplete" due to
               # idle server connections being randomly used and randomly expiring
               # under us.
               tune.idle-pool.shared off

       defaults
               mode http
               timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
               timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
               timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"

       frontend fe
               bind "fd@${fe}"
               use_backend no_vary_be if { path_beg /no_vary_support }
               default_backend test

       backend test
               http-request cache-use my_cache
               server www ${s1_addr}:${s1_port}
               http-response cache-store my_cache
               http-response set-header X-Cache-Hit %[res.cache_hit]

        backend no_vary_be
               http-request cache-use no_vary_cache
               server www ${s2_addr}:${s2_port}
               http-response cache-store no_vary_cache
               http-response set-header X-Cache-Hit %[res.cache_hit]

       cache my_cache
               total-max-size 3
               max-age 20
               max-object-size 3072
               process-vary on

       cache no_vary_cache
               total-max-size 3
               max-age 20
               max-object-size 3072
               process-vary off
} -start


client c1 -connect ${h1_fe_sock} {
       # Accept-Encoding Vary
       txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
       rxresp
       expect resp.status == 200
       expect resp.http.content-encoding == "gzip"
       expect resp.bodylen == 45

       # The response for the first request had an unacceptable `content-encoding`
       # which might happen if that's the only thing the server supports, but
       # we must not cache that and instead defer to the server.
       txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
       rxresp
       expect resp.status == 200
       expect resp.http.content-encoding == "gzip"
       expect resp.bodylen == 45
       expect resp.http.X-Cache-Hit == 0

       txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 48
       expect resp.http.content-type == "text/plain"
       expect resp.http.X-Cache-Hit == 0

       # This request matches the cache entry for the request above, despite
       # matching the `accept-encoding` of the first request because the
       # request above only has the `identity` encoding which is implicitly
       # added, unless explicitly forbidden.
       txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 48
       expect resp.http.content-type == "text/plain"
       expect resp.http.X-Cache-Hit == 1

       txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 48
       expect resp.http.content-type == "text/plain"
       expect resp.http.X-Cache-Hit == 1

       # The accept-encoding normalizer function converts the header values
       # to lower case then calculates the hash of every sub part before
       # sorting the hashes and xor'ing them (while removing duplicates).
       txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 51
       expect resp.http.X-Cache-Hit == 0

       txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 51
       expect resp.http.X-Cache-Hit == 1

       txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: second,first"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 51
       expect resp.http.X-Cache-Hit == 1

       txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: FirsT,SECOND,first"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 51
       expect resp.http.X-Cache-Hit == 1

       # Unmanaged vary
       txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 51
       expect resp.http.X-Cache-Hit == 0

       txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 51
       expect resp.http.X-Cache-Hit == 0


       # Mixed Vary (Accept-Encoding + Referer)
       txreq -url "/referer-accept-encoding" \
               -hdr "Accept-Encoding: br, gzip" \
               -hdr "Referer: referer"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 51
       expect resp.http.X-Cache-Hit == 0

       txreq -url "/referer-accept-encoding" \
               -hdr "Accept-Encoding: br" \
               -hdr "Referer: other-referer"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 54
       expect resp.http.X-Cache-Hit == 0

       txreq -url "/referer-accept-encoding" \
               -hdr "Accept-Encoding: gzip" \
               -hdr "Referer: other-referer"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 57
       expect resp.http.X-Cache-Hit == 0

       txreq -url "/referer-accept-encoding" \
               -hdr "Referer: referer" \
               -hdr "Accept-Encoding: gzip, br"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 51
       expect resp.http.X-Cache-Hit == 1

       txreq -url "/referer-accept-encoding" \
               -hdr "Accept-Encoding: br" \
               -hdr "Referer: other-referer"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 54
       expect resp.http.X-Cache-Hit == 1

       txreq -url "/referer-accept-encoding" \
               -hdr "Accept-Encoding: gzip" \
               -hdr "Referer: other-referer"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 57
       expect resp.http.X-Cache-Hit == 1


       # Mixed Vary (Accept-Encoding + Referer + Origin)
       txreq -url "/origin-referer-accept-encoding" \
               -hdr "Accept-Encoding: br, gzip" \
               -hdr "Referer: referer" \
               -hdr "Origin: origin"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 58
       expect resp.http.X-Cache-Hit == 0

       txreq -url "/origin-referer-accept-encoding" \
               -hdr "Accept-Encoding: br, gzip" \
               -hdr "Referer: referer" \
               -hdr "Origin: origin"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 58
       expect resp.http.X-Cache-Hit == 1

       txreq -url "/origin-referer-accept-encoding" \
               -hdr "Accept-Encoding: br, gzip" \
               -hdr "Referer: referer" \
               -hdr "Origin: other-origin"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 59
       expect resp.http.X-Cache-Hit == 0

       txreq -url "/origin-referer-accept-encoding" \
               -hdr "Accept-Encoding: br, gzip" \
               -hdr "Referer: referer" \
               -hdr "Origin: other-origin"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 59
       expect resp.http.X-Cache-Hit == 1

       # Multiple Accept-encoding headers
       txreq -url "/multiple_headers" \
               -hdr "Accept-Encoding: gzip" \
               -hdr "Accept-Encoding: br, deflate"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 155
       expect resp.http.X-Cache-Hit == 0

       txreq -url "/multiple_headers" \
               -hdr "Accept-Encoding: deflate" \
               -hdr "Accept-Encoding: br,gzip"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 155
       expect resp.http.X-Cache-Hit == 1

       # Should not match a cache entry
       txreq -url "/multiple_headers" \
               -hdr "Accept-Encoding: first_encoding"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 166
       expect resp.http.X-Cache-Hit == 0

       # Too many accept encodings
       txreq -url "/too_many_encodings" \
               -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 177
       expect resp.http.X-Cache-Hit == 0

       txreq -url "/too_many_encodings" \
               -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 188
       expect resp.http.X-Cache-Hit == 0

       # A missing 'Accept-Encoding' implies that anything is acceptable,
       # while an empty 'Accept-Encoding' implies nothing is acceptable.

       # Start by caching a gzip response.
       txreq -url "/empty-vs-missing" -hdr "Accept-Encoding: gzip"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 234
       expect resp.http.content-encoding == "gzip"
       expect resp.http.X-Cache-Hit == 0

       # Check that it is cached.
       txreq -url "/empty-vs-missing" -hdr "Accept-Encoding: gzip"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 234
       expect resp.http.content-encoding == "gzip"
       expect resp.http.X-Cache-Hit == 1

       # Check that the cached response is returned when no accept-encoding is
       # specified.
       txreq -url "/empty-vs-missing"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 234
       expect resp.http.content-encoding == "gzip"
       expect resp.http.X-Cache-Hit == 1

       # Check that the cached response is not returned when an empty
       # accept-encoding is specified.
       txreq -url "/empty-vs-missing" -hdr "Accept-Encoding:"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 256
       expect resp.http.content-encoding == "<undef>"
       expect resp.http.X-Cache-Hit == 0

       # The following requests are treated by a backend that does not cache
       # responses containing a Vary header
       txreq -url "/no_vary_support"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 57
       expect resp.http.X-Cache-Hit == 0

       txreq -url "/no_vary_support"
       rxresp
       expect resp.status == 200
       expect resp.bodylen == 57
       expect resp.http.X-Cache-Hit == 0


} -run