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