blob: 001018f93c55f54e301c1932e14f7c86a5f756e6 [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"
11 txresp -nolen -hdr "Transfer-Encoding: chunked" \
12 -hdr "Content-Type: gzip" \
13 -hdr "Vary: accept-encoding" \
14 -hdr "Cache-Control: max-age=5"
15 chunkedlen 15
16 chunkedlen 15
17 chunkedlen 15
18 chunkedlen 0
19
20 # Response varying on "accept-encoding"
21 rxreq
22 expect req.url == "/accept-encoding"
23 txresp -nolen -hdr "Transfer-Encoding: chunked" \
24 -hdr "Content-Type: text/plain" \
25 -hdr "Vary: accept-encoding" \
26 -hdr "Cache-Control: max-age=5"
27 chunkedlen 16
28 chunkedlen 16
29 chunkedlen 16
30 chunkedlen 0
31
32 # Response varying on "accept-encoding" but having two different encodings
33 rxreq
34 expect req.url == "/accept-encoding-multiple"
35 txresp -nolen -hdr "Transfer-Encoding: chunked" \
36 -hdr "Vary: accept-encoding" \
37 -hdr "Cache-Control: max-age=5"
38 chunkedlen 17
39 chunkedlen 17
40 chunkedlen 17
41 chunkedlen 0
42
43 # Unmanaged vary
44 rxreq
45 expect req.url == "/unmanaged"
46 txresp -nolen -hdr "Transfer-Encoding: chunked" \
47 -hdr "Vary: accept-encoding,unmanaged" \
48 -hdr "Cache-Control: max-age=5"
49 chunkedlen 17
50 chunkedlen 17
51 chunkedlen 17
52 chunkedlen 0
53
54 rxreq
55 expect req.url == "/unmanaged"
56 txresp -nolen -hdr "Transfer-Encoding: chunked" \
57 -hdr "Vary: accept-encoding,unmanaged" \
58 -hdr "Cache-Control: max-age=5"
59 chunkedlen 17
60 chunkedlen 17
61 chunkedlen 17
62 chunkedlen 0
63
64
65 # Mixed Vary (Accept-Encoding + Referer)
66 rxreq
67 expect req.url == "/referer-accept-encoding"
68 txresp -nolen -hdr "Transfer-Encoding: chunked" \
69 -hdr "Vary: accept-encoding,referer" \
70 -hdr "Cache-Control: max-age=5"
71 chunkedlen 17
72 chunkedlen 17
73 chunkedlen 17
74 chunkedlen 0
75
76 rxreq
77 expect req.url == "/referer-accept-encoding"
78 txresp -nolen -hdr "Transfer-Encoding: chunked" \
79 -hdr "Vary: referer,accept-encoding" \
80 -hdr "Cache-Control: max-age=5"
81 chunkedlen 18
82 chunkedlen 18
83 chunkedlen 18
84 chunkedlen 0
85
86 rxreq
87 expect req.url == "/referer-accept-encoding"
88 txresp -nolen -hdr "Transfer-Encoding: chunked" \
89 -hdr "Vary: referer,accept-encoding" \
90 -hdr "Cache-Control: max-age=5"
91 chunkedlen 19
92 chunkedlen 19
93 chunkedlen 19
94 chunkedlen 0
95
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +010096
97} -start
98
99server s2 {
100 # Responses that should not be cached
101 rxreq
102 expect req.url == "/no_vary_support"
103 txresp -nolen -hdr "Transfer-Encoding: chunked" \
104 -hdr "Vary: accept-encoding" \
105 -hdr "Cache-Control: max-age=5"
106 chunkedlen 19
107 chunkedlen 19
108 chunkedlen 19
109 chunkedlen 0
110
111 rxreq
112 expect req.url == "/no_vary_support"
113 txresp -nolen -hdr "Transfer-Encoding: chunked" \
114 -hdr "Vary: accept-encoding" \
115 -hdr "Cache-Control: max-age=5"
116 chunkedlen 19
117 chunkedlen 19
118 chunkedlen 19
119 chunkedlen 0
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100120} -start
121
122haproxy h1 -conf {
123 defaults
124 mode http
125 ${no-htx} option http-use-htx
126 timeout connect 1s
127 timeout client 1s
128 timeout server 1s
129
130 frontend fe
131 bind "fd@${fe}"
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100132 use_backend no_vary_be if { path_beg /no_vary_support }
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100133 default_backend test
134
135 backend test
136 http-request cache-use my_cache
137 server www ${s1_addr}:${s1_port}
138 http-response cache-store my_cache
139 http-response set-header X-Cache-Hit %[res.cache_hit]
140
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100141 backend no_vary_be
142 http-request cache-use no_vary_cache
143 server www ${s2_addr}:${s2_port}
144 http-response cache-store no_vary_cache
145 http-response set-header X-Cache-Hit %[res.cache_hit]
146
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100147 cache my_cache
148 total-max-size 3
149 max-age 20
150 max-object-size 3072
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100151 process-vary 1
152
153 cache no_vary_cache
154 total-max-size 3
155 max-age 20
156 max-object-size 3072
157 process-vary 0
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100158} -start
159
160
161client c1 -connect ${h1_fe_sock} {
162 # Accept-Encoding Vary
163 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
164 rxresp
165 expect resp.status == 200
166 expect resp.http.content-type == "gzip"
167 expect resp.bodylen == 45
168
169 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
170 rxresp
171 expect resp.status == 200
172 expect resp.bodylen == 48
173 expect resp.http.content-type == "text/plain"
174 expect resp.http.X-Cache-Hit == 0
175
176 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
177 rxresp
178 expect resp.status == 200
179 expect resp.bodylen == 45
180 expect resp.http.content-type == "gzip"
181 expect resp.http.X-Cache-Hit == 1
182
183 txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
184 rxresp
185 expect resp.status == 200
186 expect resp.bodylen == 48
187 expect resp.http.content-type == "text/plain"
188 expect resp.http.X-Cache-Hit == 1
189
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100190 # The accept-encoding normalizer function converts the header values
191 # to lower case then calculates the hash of every sub part before
192 # sorting the hashes and xor'ing them (while removing duplicates).
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100193 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
194 rxresp
195 expect resp.status == 200
196 expect resp.bodylen == 51
197 expect resp.http.X-Cache-Hit == 0
198
199 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
200 rxresp
201 expect resp.status == 200
202 expect resp.bodylen == 51
203 expect resp.http.X-Cache-Hit == 1
204
205 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: second,first"
206 rxresp
207 expect resp.status == 200
208 expect resp.bodylen == 51
209 expect resp.http.X-Cache-Hit == 1
210
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100211 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: FirsT,SECOND,first"
212 rxresp
213 expect resp.status == 200
214 expect resp.bodylen == 51
215 expect resp.http.X-Cache-Hit == 1
216
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100217 # Unmanaged vary
218 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
219 rxresp
220 expect resp.status == 200
221 expect resp.bodylen == 51
222 expect resp.http.X-Cache-Hit == 0
223
224 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
225 rxresp
226 expect resp.status == 200
227 expect resp.bodylen == 51
228 expect resp.http.X-Cache-Hit == 0
229
230
231 # Mixed Vary (Accept-Encoding + Referer)
232 txreq -url "/referer-accept-encoding" \
233 -hdr "Accept-Encoding: first_value,second_value" \
234 -hdr "Referer: referer"
235 rxresp
236 expect resp.status == 200
237 expect resp.bodylen == 51
238 expect resp.http.X-Cache-Hit == 0
239
240 txreq -url "/referer-accept-encoding" \
241 -hdr "Accept-Encoding: first_value" \
242 -hdr "Referer: other-referer"
243 rxresp
244 expect resp.status == 200
245 expect resp.bodylen == 54
246 expect resp.http.X-Cache-Hit == 0
247
248 txreq -url "/referer-accept-encoding" \
249 -hdr "Accept-Encoding: second_value" \
250 -hdr "Referer: other-referer"
251 rxresp
252 expect resp.status == 200
253 expect resp.bodylen == 57
254 expect resp.http.X-Cache-Hit == 0
255
256 txreq -url "/referer-accept-encoding" \
257 -hdr "Referer: referer" \
258 -hdr "Accept-Encoding: second_value,first_value"
259 rxresp
260 expect resp.status == 200
261 expect resp.bodylen == 51
262 expect resp.http.X-Cache-Hit == 1
263
264 txreq -url "/referer-accept-encoding" \
265 -hdr "Accept-Encoding: first_value" \
266 -hdr "Referer: other-referer"
267 rxresp
268 expect resp.status == 200
269 expect resp.bodylen == 54
270 expect resp.http.X-Cache-Hit == 1
271
272 txreq -url "/referer-accept-encoding" \
273 -hdr "Accept-Encoding: second_value" \
274 -hdr "Referer: other-referer"
275 rxresp
276 expect resp.status == 200
277 expect resp.bodylen == 57
278 expect resp.http.X-Cache-Hit == 1
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100279
Remi Tricot-Le Breton8bb72aa2020-11-30 17:06:03 +0100280 # The following requests are treated by a backend that does not cache
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100281 # responses containing a Vary header
282 txreq -url "/no_vary_support"
283 rxresp
284 expect resp.status == 200
285 expect resp.bodylen == 57
286 expect resp.http.X-Cache-Hit == 0
287
288 txreq -url "/no_vary_support"
289 rxresp
290 expect resp.status == 200
291 expect resp.bodylen == 57
292 expect resp.http.X-Cache-Hit == 0
293
294
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100295} -run