blob: 969049042761a8ee32e99ae31464426a3b764715 [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
190 # The accept-encoding normalizer function sorts alphabeticaly the values
191 # before calculating the secondary key
192 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
193 rxresp
194 expect resp.status == 200
195 expect resp.bodylen == 51
196 expect resp.http.X-Cache-Hit == 0
197
198 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
199 rxresp
200 expect resp.status == 200
201 expect resp.bodylen == 51
202 expect resp.http.X-Cache-Hit == 1
203
204 txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: second,first"
205 rxresp
206 expect resp.status == 200
207 expect resp.bodylen == 51
208 expect resp.http.X-Cache-Hit == 1
209
210 # Unmanaged vary
211 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
212 rxresp
213 expect resp.status == 200
214 expect resp.bodylen == 51
215 expect resp.http.X-Cache-Hit == 0
216
217 txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
218 rxresp
219 expect resp.status == 200
220 expect resp.bodylen == 51
221 expect resp.http.X-Cache-Hit == 0
222
223
224 # Mixed Vary (Accept-Encoding + Referer)
225 txreq -url "/referer-accept-encoding" \
226 -hdr "Accept-Encoding: first_value,second_value" \
227 -hdr "Referer: referer"
228 rxresp
229 expect resp.status == 200
230 expect resp.bodylen == 51
231 expect resp.http.X-Cache-Hit == 0
232
233 txreq -url "/referer-accept-encoding" \
234 -hdr "Accept-Encoding: first_value" \
235 -hdr "Referer: other-referer"
236 rxresp
237 expect resp.status == 200
238 expect resp.bodylen == 54
239 expect resp.http.X-Cache-Hit == 0
240
241 txreq -url "/referer-accept-encoding" \
242 -hdr "Accept-Encoding: second_value" \
243 -hdr "Referer: other-referer"
244 rxresp
245 expect resp.status == 200
246 expect resp.bodylen == 57
247 expect resp.http.X-Cache-Hit == 0
248
249 txreq -url "/referer-accept-encoding" \
250 -hdr "Referer: referer" \
251 -hdr "Accept-Encoding: second_value,first_value"
252 rxresp
253 expect resp.status == 200
254 expect resp.bodylen == 51
255 expect resp.http.X-Cache-Hit == 1
256
257 txreq -url "/referer-accept-encoding" \
258 -hdr "Accept-Encoding: first_value" \
259 -hdr "Referer: other-referer"
260 rxresp
261 expect resp.status == 200
262 expect resp.bodylen == 54
263 expect resp.http.X-Cache-Hit == 1
264
265 txreq -url "/referer-accept-encoding" \
266 -hdr "Accept-Encoding: second_value" \
267 -hdr "Referer: other-referer"
268 rxresp
269 expect resp.status == 200
270 expect resp.bodylen == 57
271 expect resp.http.X-Cache-Hit == 1
Remi Tricot-Le Breton754b2422020-11-16 15:56:10 +0100272
273 # The following requests are trated by a backend that does not cache
274 # responses containing a Vary header
275 txreq -url "/no_vary_support"
276 rxresp
277 expect resp.status == 200
278 expect resp.bodylen == 57
279 expect resp.http.X-Cache-Hit == 0
280
281 txreq -url "/no_vary_support"
282 rxresp
283 expect resp.status == 200
284 expect resp.bodylen == 57
285 expect resp.http.X-Cache-Hit == 0
286
287
Remi Tricot-Le Breton1785f3d2020-11-16 15:56:09 +0100288} -run