blob: 5d9eadabde00119bd860063c6877765a8f355d23 [file] [log] [blame]
Christopher Faulete98ce252018-12-21 15:24:57 +01001varnishtest "Basic compression test"
2
Christopher Faulete98ce252018-12-21 15:24:57 +01003#REQUIRE_OPTION=ZLIB|SLZ
4
5feature ignore_unknown_macro
6
7server s1 {
8 # client c1 - request 1
9 rxreq
10 expect req.url == "/c1.1"
11 expect req.http.accept-encoding == "<undef>"
12 txresp \
13 -hdr "Content-Type: text/plain" \
14 -bodylen 100
15
16 # client c1 - request 2
17 rxreq
18 expect req.url == "/c1.2"
19 expect req.http.user-agent == "Mozilla/4"
20 expect req.http.accept-encoding == "gzip"
21 txresp \
22 -hdr "Content-Type: text/plain" \
23 -bodylen 100
24
25 # client c1 - request 3
26 rxreq
27 expect req.url == "/c1.3"
28 expect req.proto == "HTTP/1.0"
29 expect req.http.accept-encoding == "gzip"
30 txresp -bodylen 100
31
32 # client c1 - request 4
33 rxreq
34 expect req.url == "/c1.4"
35 expect req.http.accept-encoding == "gzip"
36 txresp \
37 -proto "HTTP/1.0" \
38 -hdr "Connection: keep-alive" \
39 -hdr "Content-Type: text/plain" \
40 -bodylen 100
41
42 # client c1 - request 5
43 rxreq
44 expect req.url == "/c1.5"
45 expect req.method == "HEAD"
46 expect req.http.accept-encoding == "gzip"
47 txresp -nolen \
48 -hdr "Content-Length: 100" \
49 -hdr "Content-Type: text/plain" \
50
51 # client c1 - request 6
52 rxreq
53 expect req.url == "/c1.6"
54 expect req.http.accept-encoding == "gzip"
55 txresp \
56 -status 400 \
57 -hdr "Content-Type: text/plain" \
58 -bodylen 100
59
60 # client c1 - request 7
61 rxreq
62 expect req.url == "/c1.7"
63 expect req.http.accept-encoding == "gzip"
64 txresp \
65 -hdr "Content-Type: text/plain" \
66 -hdr "Content-Encoding: something" \
67 -body "FOO"
68
69 # client c1 - request 8
70 rxreq
71 expect req.url == "/c1.8"
72 expect req.http.accept-encoding == "gzip"
73 txresp \
74 -hdr "Content-Type: text/plain" \
75 -hdr "Cache-Control: no-transform" \
76 -bodylen 100
77
78 # client c1 - request 9
79 rxreq
80 expect req.url == "/c1.9"
81 expect req.http.accept-encoding == "gzip"
82 txresp \
83 -hdr "Content-Type: text/css" \
84 -bodylen 100
85
86 # client c1 - request 10
87 rxreq
88 expect req.url == "/c1.10"
89 expect req.http.accept-encoding == "gzip"
90 txresp \
91 -hdr "Content-Type: multipart/mixed; boundary=\"aaa\"" \
92 -bodylen 100
93
94 # Close the connection with HAProxy and wait for a new one
95 # (C1 has finished and C2 will start)
96 accept
97
98 # client c2 - request 1
99 rxreq
100 expect req.url == "/c2.1"
101 expect req.http.accept-encoding == "gzip"
102 txresp \
103 -hdr "Content-Type: text/plain" \
104 -bodylen 100
105
106 # client c2 - request 2
107 rxreq
108 expect req.url == "/c2.2"
109 expect req.http.accept-encoding == "gzip"
110 txresp -nolen \
111 -hdr "Content-Type: text/plain" \
112 -hdr "Transfer-Encoding: chunked"
113 chunkedlen 1
114 chunkedlen 1
115 chunkedlen 2
116 chunkedlen 3
117 chunkedlen 5
118 chunkedlen 8
119 chunkedlen 13
120 chunkedlen 21
121 chunkedlen 34
122 chunkedlen 55
123 chunkedlen 89
124 chunkedlen 144
125 chunkedlen 233
126 chunkedlen 0
127
128 # Close the connection with HAProxy and wait for a new one
129 # (C2 has finished and C3 will start)
130 accept
131
132 # client c3 - request 1
133 rxreq
134 expect req.url == "/c3.1"
135 expect req.http.accept-encoding == "<undef>"
136 txresp \
137 -hdr "Content-Type: text/plain" \
138 -bodylen 50000
139
140 # client c3 - request 2
141 rxreq
142 expect req.url == "/c3.2"
143 expect req.http.accept-encoding == "<undef>"
144 txresp -nolen \
145 -hdr "Content-Type: text/plain" \
146 -hdr "Transfer-Encoding: chunked"
147 chunkedlen 1000
148 chunkedlen 1000
149 chunkedlen 1000
150 chunkedlen 1000
151 chunkedlen 1000
152 chunkedlen 5000
153 chunkedlen 10000
154 chunkedlen 30000
155 chunkedlen 0
156
157 # Close the connection with HAProxy and wait for a new one
158 # (C3 has finished and C4 will start)
159 accept
160
161 # client c4 - request 1
162 rxreq
163 expect req.url == "/c4.1"
164 expect req.http.accept-encoding == "<undef>"
165 txresp \
166 -hdr "Content-Type: text/plain" \
167 -bodylen 100
168
169 # client c4 - request 2
170 rxreq
171 expect req.url == "/c4.2"
172 expect req.http.accept-encoding == "<undef>"
173 txresp \
174 -hdr "Content-Type: text/plain" \
175 -bodylen 100
176} -start
177
178
179haproxy h1 -conf {
180 defaults
181 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +0100182 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
183 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
184 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
Christopher Faulete98ce252018-12-21 15:24:57 +0100185
186 frontend fe-gzip
187 bind "fd@${fe_gzip}"
188 default_backend be-gzip
189
190 frontend fe-identity
191 bind "fd@${fe_identity}"
192 default_backend be-identity
193
194 frontend fe-gzip-deflate
195 bind "fd@${fe_gzip_deflate}"
196 default_backend be-gzip-defalte
197
198 backend be-gzip
199 compression algo gzip
200 compression type text/html text/plain
201 server www ${s1_addr}:${s1_port}
202
203 backend be-identity
204 compression algo identity
205 server www ${s1_addr}:${s1_port}
206
207 backend be-gzip-defalte
208 compression algo gzip deflate
209 compression offload
210 server www ${s1_addr}:${s1_port}
211
212} -start
213
214# No compression expected because not supported by the client or because
215# something in the request or response headers forbids it.
216client c1 -connect ${h1_fe_gzip_sock} {
217 # 1. no "Accept-Encoding header"
218 txreq -url "/c1.1"
219 rxresp
220 expect resp.status == 200
221 expect resp.http.content-encoding == "<undef>"
222 expect resp.http.transfer-encoding == "<undef>"
223 expect resp.bodylen == 100
224
225 # 2. Buggy User-Agent
226 txreq -url "/c1.2" \
227 -hdr "Accept-Encoding: gzip" \
228 -hdr "User-Agent: Mozilla/4"
229 rxresp
230 expect resp.status == 200
231 expect resp.http.content-encoding == "<undef>"
232 expect resp.http.transfer-encoding == "<undef>"
233 expect resp.bodylen == 100
234
235 # 3. HTTP/1.0 request
236 txreq -url "/c1.3" \
237 -proto "HTTP/1.0" \
238 -hdr "Accept-Encoding: gzip" \
239 -hdr "Connection: keep-alive"
240 rxresp
241 expect resp.status == 200
242 expect resp.http.content-encoding == "<undef>"
243 expect resp.http.transfer-encoding == "<undef>"
244 expect resp.bodylen == 100
245
246 # 4. HTTP/1.0 response
247 txreq -url "/c1.4" \
248 -hdr "Accept-Encoding: gzip"
249 rxresp
250 expect resp.status == 200
251 expect resp.proto == "HTTP/1.0"
252 expect resp.http.content-encoding == "<undef>"
253 expect resp.http.transfer-encoding == "<undef>"
254 expect resp.bodylen == 100
255
256 # 5. HEAD method
257 txreq -req "HEAD" -url "/c1.5" \
258 -hdr "Accept-Encoding: gzip"
259 rxresp -no_obj
260 expect resp.status == 200
261 expect resp.http.content-length == "100"
262 expect resp.http.content-encoding == "<undef>"
263 expect resp.http.transfer-encoding == "<undef>"
264
265 # 6. Response status code != 20[0-3]
266 txreq -url "/c1.6" \
267 -hdr "Accept-Encoding: gzip"
268 rxresp
269 expect resp.status == 400
270 expect resp.http.content-encoding == "<undef>"
271 expect resp.http.transfer-encoding == "<undef>"
272 expect resp.bodylen == 100
273
274 # 7. Response alerady compressed by the server (with "Accept-Encoding")
275 txreq -url "/c1.7" \
276 -hdr "Accept-Encoding: gzip"
277 rxresp
278 expect resp.status == 200
279 expect resp.http.content-encoding == "something"
280 expect resp.http.transfer-encoding == "<undef>"
281 expect resp.bodylen == 3
282 expect resp.body == "FOO"
283
284 # 8. Response with "Cache-Control: no-transform"
285 txreq -url "/c1.8" \
286 -hdr "Accept-Encoding: gzip"
287 rxresp
288 expect resp.status == 200
289 expect resp.http.content-encoding == "<undef>"
290 expect resp.http.transfer-encoding == "<undef>"
291 expect resp.http.cache-control == "no-transform"
292 expect resp.bodylen == 100
293
294 # 9. Response with uncompressable content-type
295 txreq -url "/c1.9" \
296 -hdr "Accept-Encoding: gzip"
297 rxresp
298 expect resp.status == 200
299 expect resp.http.content-encoding == "<undef>"
300 expect resp.http.transfer-encoding == "<undef>"
301 expect resp.http.content-type == "text/css"
302 expect resp.bodylen == 100
303
304 # 10. Response with uncompressable content-type
305 txreq -url "/c1.10" \
306 -hdr "Accept-Encoding: gzip"
307 rxresp
308 expect resp.status == 200
309 expect resp.http.content-encoding == "<undef>"
310 expect resp.http.transfer-encoding == "<undef>"
311 expect resp.http.content-type == "multipart/mixed; boundary=\"aaa\""
312 expect resp.bodylen == 100
313} -run
314
315# GZIP Compression expected (small body)
316client c2 -connect ${h1_fe_gzip_sock} {
317 # 1. response from the server with a small body with a C-L
318 txreq -url "/c2.1" \
319 -hdr "Accept-Encoding: gzip"
320 rxresp
321 expect resp.status == 200
322 expect resp.http.content-encoding == "gzip"
323 expect resp.http.transfer-encoding == "chunked"
324 gunzip
325 expect resp.bodylen == 100
326
327 # 2. response from the server with a small chunked body
328 txreq -url "/c2.2" \
329 -hdr "Accept-Encoding: gzip"
330 rxresp
331 expect resp.status == 200
332 expect resp.http.content-encoding == "gzip"
333 expect resp.http.transfer-encoding == "chunked"
334 gunzip
335 expect resp.bodylen == 609
336} -run
337
338# Identity compression expect (Huge body)
339# Identity is used because of a limitation of vtest (the uncompressed body size
340# must be lower than 10 times of the compressed one)
341client c3 -connect ${h1_fe_identity_sock} {
342 # 1. response from the server with a huge body with a C-L
343 txreq -url "/c3.1"
344 rxresp
345 expect resp.status == 200
346 expect resp.http.content-encoding == "<undef>"
347 expect resp.http.transfer-encoding == "chunked"
348 expect resp.bodylen == 50000
349
350 # 2. response from the server with a huge chunked body
351 txreq -url "/c3.2"
352 rxresp
353 expect resp.status == 200
354 expect resp.http.content-encoding == "<undef>"
355 expect resp.http.transfer-encoding == "chunked"
356 expect resp.bodylen == 50000
357} -run
358
359
360# Compression expected with priority
361client c4 -connect ${h1_fe_gzip_deflate_sock} {
362 # 1. response from the server with a small body with a C-L
363 txreq -url "/c4.1" \
364 -hdr "Accept-Encoding: *;q=0, gzip;q=0.750, deflate;q=0.500"
365 rxresp
366 expect resp.status == 200
367 expect resp.http.content-encoding == "gzip"
368 expect resp.http.transfer-encoding == "chunked"
369
370 # 2. response from the server with a small body with a C-L
371 txreq -url "/c4.2" \
372 -hdr "Accept-Encoding: *;q=0, gzip;q=0.500, deflate;q=0.750"
373 rxresp
374 expect resp.status == 200
375 expect resp.http.content-encoding == "deflate"
376 expect resp.http.transfer-encoding == "chunked"
377} -run