blob: afd2cfbd538754bea68deb8c932d64adaaceb9e3 [file] [log] [blame]
Remi Tricot-Le Breton14df1e12020-12-23 18:13:51 +01001varnishtest "Check the Accept-Encoding processing implemented in the Vary mechanism"
2
3#REQUIRE_VERSION=2.4
4
5feature ignore_unknown_macro
6
7server s1 {
8 # Response varying on "accept-encoding" with a gzip content-encoding
9 rxreq
10 expect req.url == "/accept-encoding"
11 txresp -hdr "Content-Encoding: gzip" \
12 -hdr "Vary: accept-encoding" \
13 -hdr "Cache-Control: max-age=5" \
14 -bodylen 45
15
16 # Response varying on "accept-encoding" with a deflate content-encoding
17 rxreq
18 expect req.url == "/accept-encoding"
19 txresp -hdr "Content-Encoding: deflate" \
20 -hdr "Vary: accept-encoding" \
21 -hdr "Cache-Control: max-age=5" \
22 -bodylen 55
23
24
25 # Response varying on "accept-encoding" with no content-encoding (identity)
26 rxreq
27 expect req.url == "/accept-encoding-identity"
28 txresp -hdr "Vary: accept-encoding" \
29 -hdr "Cache-Control: max-age=5" \
30 -bodylen 65
31
32 # Response varying on "accept-encoding" with refused identity encoding
33 rxreq
34 expect req.url == "/accept-encoding-identity"
35 txresp -hdr "Vary: accept-encoding" \
36 -hdr "Cache-Control: max-age=5" \
37 -hdr "Content-Encoding: deflate" \
38 -bodylen 75
39
40
41 rxreq
42 expect req.url == "/accept-encoding-star"
43 txresp -hdr "Vary: accept-encoding" \
44 -hdr "Cache-Control: max-age=5" \
45 -hdr "Content-Encoding: br" \
46 -bodylen 89
47
48 rxreq
49 expect req.url == "/accept-encoding-star"
50 txresp -hdr "Vary: accept-encoding" \
51 -hdr "Cache-Control: max-age=5" \
52 -hdr "Content-Encoding: deflate" \
53 -bodylen 99
54
55
56 rxreq
57 expect req.url == "/multiple-content-encoding"
58 txresp -hdr "Vary: accept-encoding" \
59 -hdr "Cache-Control: max-age=5" \
60 -hdr "Content-Encoding: deflate, gzip" \
61 -bodylen 109
62
63 rxreq
64 expect req.url == "/unknown-content-encoding"
65 txresp -hdr "Vary: accept-encoding" \
66 -hdr "Cache-Control: max-age=5" \
67 -hdr "Content-Encoding: unknown_encoding" \
68 -bodylen 119
69
70 rxreq
71 expect req.url == "/unknown-content-encoding"
72 txresp -hdr "Vary: accept-encoding" \
73 -hdr "Cache-Control: max-age=5" \
74 -hdr "Content-Encoding: unknown_encoding" \
75 -bodylen 119
76} -start
77
78
79haproxy h1 -conf {
80 defaults
81 mode http
82 ${no-htx} option http-use-htx
83 timeout connect 1s
84 timeout client 1s
85 timeout server 1s
86
87 frontend fe
88 bind "fd@${fe}"
89 default_backend test
90
91 backend test
92 http-request cache-use my_cache
93 server www ${s1_addr}:${s1_port}
94 http-response cache-store my_cache
95 http-response set-header X-Cache-Hit %[res.cache_hit]
96
97 cache my_cache
98 total-max-size 3
99 max-age 20
100 max-object-size 3072
Remi Tricot-Le Bretone6cc5b52020-12-23 18:13:53 +0100101 process-vary on
Remi Tricot-Le Breton14df1e12020-12-23 18:13:51 +0100102} -start
103
104
105client c1 -connect ${h1_fe_sock} {
106 #
107 # Accept-Encoding Vary
108 #
109
110 # First request
111 txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip"
112 rxresp
113 expect resp.status == 200
114 expect resp.http.content-encoding == "gzip"
115 expect resp.bodylen == 45
116
117 # Regular case
118 txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip"
119 rxresp
120 expect resp.status == 200
121 expect resp.http.content-encoding == "gzip"
122 expect resp.bodylen == 45
123 expect resp.http.X-Cache-Hit == 1
124
125 # Regular case with upper case encoding
126 txreq -url "/accept-encoding" -hdr "Accept-Encoding: GZIP"
127 rxresp
128 expect resp.status == 200
129 expect resp.http.content-encoding == "gzip"
130 expect resp.bodylen == 45
131 expect resp.http.X-Cache-Hit == 1
132
133 # Multiple accepted encodings (all standard)
134 txreq -url "/accept-encoding" -hdr "Accept-Encoding: deflate,gzip"
135 rxresp
136 expect resp.status == 200
137 expect resp.http.content-encoding == "gzip"
138 expect resp.bodylen == 45
139 expect resp.http.X-Cache-Hit == 1
140
141 # Multiple accept-encoding headers + non-standard accepted encodings
142 txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_encoding,second_encoding" -hdr "Accept-Encoding: gzip"
143 rxresp
144 expect resp.status == 200
145 expect resp.http.content-encoding == "gzip"
146 expect resp.bodylen == 45
147 expect resp.http.X-Cache-Hit == 1
148
149 # Regular case with positive weight
150 txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip;q=0.8"
151 rxresp
152 expect resp.status == 200
153 expect resp.http.content-encoding == "gzip"
154 expect resp.bodylen == 45
155 expect resp.http.X-Cache-Hit == 1
156
157 # Regular case with positive weight and extra whitespaces
158 txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip ; q=0.8"
159 rxresp
160 expect resp.status == 200
161 expect resp.http.content-encoding == "gzip"
162 expect resp.bodylen == 45
163 expect resp.http.X-Cache-Hit == 1
164
165 # Regular case with null weight
166 txreq -url "/accept-encoding" -hdr "Accept-Encoding: deflate;q=0.8, gzip;q=0"
167 rxresp
168 expect resp.status == 200
169 expect resp.http.content-encoding == "deflate"
170 expect resp.bodylen == 55
171 expect resp.http.X-Cache-Hit == 0
172
173
174 #
175 # Identity tests
176 #
177 txreq -url "/accept-encoding-identity"
178 rxresp
179 expect resp.status == 200
180 expect resp.http.content-encoding == "<undef>"
181 expect resp.bodylen == 65
182 expect resp.http.X-Cache-Hit == 0
183
184 # Regular case
185 txreq -url "/accept-encoding-identity"
186 rxresp
187 expect resp.status == 200
188 expect resp.http.content-encoding == "<undef>"
189 expect resp.bodylen == 65
190 expect resp.http.X-Cache-Hit == 1
191
192 # Identity is allowed by default even if another encoding is specified
193 txreq -url "/accept-encoding-identity" -hdr "Accept-Encoding: gzip"
194 rxresp
195 expect resp.status == 200
196 expect resp.http.content-encoding == "<undef>"
197 expect resp.bodylen == 65
198 expect resp.http.X-Cache-Hit == 1
199
200 # Refused identity encoding (explicit null weight)
201 txreq -url "/accept-encoding-identity" -hdr "Accept-Encoding: deflate, identity;q=0"
202 rxresp
203 expect resp.status == 200
204 expect resp.http.content-encoding == "deflate"
205 expect resp.bodylen == 75
206 expect resp.http.X-Cache-Hit == 0
207
208
209 #
210 # Star tests
211 #
212 txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: *"
213 rxresp
214 expect resp.status == 200
215 expect resp.http.content-encoding == "br"
216 expect resp.bodylen == 89
217 expect resp.http.X-Cache-Hit == 0
218
219 # Regular case
220 txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: *"
221 rxresp
222 expect resp.status == 200
223 expect resp.http.content-encoding == "br"
224 expect resp.bodylen == 89
225 expect resp.http.X-Cache-Hit == 1
226
227 # Reject some encodings
228 txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*"
229 rxresp
230 expect resp.status == 200
231 expect resp.http.content-encoding == "br"
232 expect resp.bodylen == 89
233 expect resp.http.X-Cache-Hit == 1
234
235 # Weighted star
236 txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*;q=0.1"
237 rxresp
238 expect resp.status == 200
239 expect resp.http.content-encoding == "br"
240 expect resp.bodylen == 89
241 expect resp.http.X-Cache-Hit == 1
242
243 # Rejected identity
244 txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*;q=0.1,identity;q=0"
245 rxresp
246 expect resp.status == 200
247 expect resp.http.content-encoding == "br"
248 expect resp.bodylen == 89
249 expect resp.http.X-Cache-Hit == 1
250
251 # Rejected star and "br" not accepted
252 txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*;q=0"
253 rxresp
254 expect resp.status == 200
255 expect resp.http.content-encoding == "deflate"
256 expect resp.bodylen == 99
257 expect resp.http.X-Cache-Hit == 0
258
259
260 #
261 # Multiple content-encodings
262 #
263 txreq -url "/multiple-content-encoding" -hdr "Accept-Encoding: gzip;q=0.8, deflate"
264 rxresp
265 expect resp.status == 200
266 expect resp.http.content-encoding == "deflate, gzip"
267 expect resp.bodylen == 109
268 expect resp.http.X-Cache-Hit == 0
269
270 txreq -url "/multiple-content-encoding" -hdr "Accept-Encoding: deflate,gzip;q=0.7"
271 rxresp
272 expect resp.status == 200
273 expect resp.http.content-encoding == "deflate, gzip"
274 expect resp.bodylen == 109
275 expect resp.http.X-Cache-Hit == 1
276
277
278 #
279 # Unknown content-encoding
280 #
281 txreq -url "/unknown-content-encoding" -hdr "Accept-Encoding: gzip;q=0.8, deflate, first_encoding"
282 rxresp
283 expect resp.status == 200
284 expect resp.http.content-encoding == "unknown_encoding"
285 expect resp.bodylen == 119
286 expect resp.http.X-Cache-Hit == 0
287
288 txreq -url "/unknown-content-encoding" -hdr "Accept-Encoding: deflate,gzip;q=0.8, first_encoding"
289 rxresp
290 expect resp.status == 200
291 expect resp.http.content-encoding == "unknown_encoding"
292 expect resp.bodylen == 119
293 expect resp.http.X-Cache-Hit == 1
294
295 # Different set of accepted encodings
296 txreq -url "/unknown-content-encoding" -hdr "Accept-Encoding: deflate, first_encoding"
297 rxresp
298 expect resp.status == 200
299 expect resp.http.content-encoding == "unknown_encoding"
300 expect resp.bodylen == 119
301 expect resp.http.X-Cache-Hit == 0
302
303} -run