summaryrefslogtreecommitdiffstats
path: root/reg-tests/compression/basic.vtc
blob: 76ad43dc374401eecee65286eb9772edb8b4a975 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
varnishtest "Basic compression test"

#REQUIRE_VERSION=1.9
#REQUIRE_OPTION=ZLIB|SLZ

feature ignore_unknown_macro

server s1 {
        # client c1 - request 1
        rxreq
        expect req.url == "/c1.1"
        expect req.http.accept-encoding == "<undef>"
        txresp \
          -hdr "Content-Type: text/plain" \
          -bodylen 100

        # client c1 - request 2
        rxreq
        expect req.url == "/c1.2"
        expect req.http.user-agent == "Mozilla/4"
        expect req.http.accept-encoding == "gzip"
        txresp \
          -hdr "Content-Type: text/plain" \
          -bodylen 100

        # client c1 - request 3
        rxreq
        expect req.url == "/c1.3"
        expect req.proto == "HTTP/1.0"
        expect req.http.accept-encoding == "gzip"
        txresp -bodylen 100

        # client c1 - request 4
        rxreq
        expect req.url == "/c1.4"
        expect req.http.accept-encoding == "gzip"
        txresp \
          -proto "HTTP/1.0" \
          -hdr "Connection: keep-alive" \
          -hdr "Content-Type: text/plain" \
          -bodylen 100

        # client c1 - request 5
        rxreq
        expect req.url == "/c1.5"
        expect req.method == "HEAD"
        expect req.http.accept-encoding == "gzip"
        txresp -nolen \
          -hdr "Content-Length: 100" \
          -hdr "Content-Type: text/plain" \

        # client c1 - request 6
        rxreq
        expect req.url == "/c1.6"
        expect req.http.accept-encoding == "gzip"
        txresp \
          -status 400 \
          -hdr "Content-Type: text/plain" \
          -bodylen 100

        # client c1 - request 7
        rxreq
        expect req.url == "/c1.7"
        expect req.http.accept-encoding == "gzip"
        txresp \
          -hdr "Content-Type: text/plain" \
          -hdr "Content-Encoding: something" \
          -body "FOO"

        # client c1 - request 8
        rxreq
        expect req.url == "/c1.8"
        expect req.http.accept-encoding == "gzip"
        txresp \
          -hdr "Content-Type: text/plain" \
          -hdr "Cache-Control: no-transform" \
          -bodylen 100

        # client c1 - request 9
        rxreq
        expect req.url == "/c1.9"
        expect req.http.accept-encoding == "gzip"
        txresp \
          -hdr "Content-Type: text/css" \
          -bodylen 100

        # client c1 - request 10
        rxreq
        expect req.url == "/c1.10"
        expect req.http.accept-encoding == "gzip"
        txresp \
          -hdr "Content-Type: multipart/mixed; boundary=\"aaa\"" \
          -bodylen 100

        # Close the connection with HAProxy and wait for a new one
        # (C1 has finished and C2 will start)
        accept

        # client c2 - request 1
        rxreq
        expect req.url == "/c2.1"
        expect req.http.accept-encoding == "gzip"
        txresp \
          -hdr "Content-Type: text/plain" \
          -bodylen 100

        # client c2 - request 2
        rxreq
        expect req.url == "/c2.2"
        expect req.http.accept-encoding == "gzip"
        txresp  -nolen \
          -hdr "Content-Type: text/plain" \
          -hdr "Transfer-Encoding: chunked"
        chunkedlen 1
        chunkedlen 1
        chunkedlen 2
        chunkedlen 3
        chunkedlen 5
        chunkedlen 8
        chunkedlen 13
        chunkedlen 21
        chunkedlen 34
        chunkedlen 55
        chunkedlen 89
        chunkedlen 144
        chunkedlen 233
        chunkedlen 0

        # Close the connection with HAProxy and wait for a new one
        # (C2 has finished and C3 will start)
        accept

        # client c3 - request 1
        rxreq
        expect req.url == "/c3.1"
        expect req.http.accept-encoding == "<undef>"
        txresp \
          -hdr "Content-Type: text/plain" \
          -bodylen 50000

        # client c3 - request 2
        rxreq
        expect req.url == "/c3.2"
        expect req.http.accept-encoding == "<undef>"
        txresp  -nolen \
          -hdr "Content-Type: text/plain" \
          -hdr "Transfer-Encoding: chunked"
        chunkedlen 1000
        chunkedlen 1000
        chunkedlen 1000
        chunkedlen 1000
        chunkedlen 1000
        chunkedlen 5000
        chunkedlen 10000
        chunkedlen 30000
        chunkedlen 0

        # Close the connection with HAProxy and wait for a new one
        # (C3 has finished and C4 will start)
        accept

        # client c4 - request 1
        rxreq
        expect req.url == "/c4.1"
        expect req.http.accept-encoding == "<undef>"
        txresp \
          -hdr "Content-Type: text/plain" \
          -bodylen 100

        # client c4 - request 2
        rxreq
        expect req.url == "/c4.2"
        expect req.http.accept-encoding == "<undef>"
        txresp \
          -hdr "Content-Type: text/plain" \
          -bodylen 100
} -start


haproxy h1 -conf {
    defaults
        mode http
        timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
        timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
        timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"

    frontend fe-gzip
        bind "fd@${fe_gzip}"
        default_backend be-gzip

    frontend fe-identity
        bind "fd@${fe_identity}"
        default_backend be-identity

    frontend fe-gzip-deflate
        bind "fd@${fe_gzip_deflate}"
        default_backend be-gzip-defalte

    backend be-gzip
        compression algo gzip
        compression type text/html text/plain
        server www ${s1_addr}:${s1_port}

    backend be-identity
        compression algo identity
        server www ${s1_addr}:${s1_port}

    backend be-gzip-defalte
        compression algo gzip deflate
	compression offload
        server www ${s1_addr}:${s1_port}

} -start

# No compression expected because not supported by the client or because
# something in the request or response headers forbids it.
client c1 -connect ${h1_fe_gzip_sock} {
        # 1. no "Accept-Encoding header"
        txreq -url "/c1.1"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "<undef>"
        expect resp.http.transfer-encoding == "<undef>"
        expect resp.bodylen == 100

        # 2. Buggy User-Agent
        txreq  -url "/c1.2" \
          -hdr "Accept-Encoding: gzip" \
          -hdr "User-Agent: Mozilla/4"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "<undef>"
        expect resp.http.transfer-encoding == "<undef>"
        expect resp.bodylen == 100

        # 3. HTTP/1.0 request
        txreq  -url "/c1.3" \
          -proto "HTTP/1.0" \
          -hdr "Accept-Encoding: gzip" \
          -hdr "Connection: keep-alive"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "<undef>"
        expect resp.http.transfer-encoding == "<undef>"
        expect resp.bodylen == 100

        # 4. HTTP/1.0 response
        txreq  -url "/c1.4" \
          -hdr "Accept-Encoding: gzip"
        rxresp
        expect resp.status == 200
        expect resp.proto == "HTTP/1.0"
        expect resp.http.content-encoding == "<undef>"
        expect resp.http.transfer-encoding == "<undef>"
        expect resp.bodylen == 100

        # 5. HEAD method
        txreq -req "HEAD" -url "/c1.5" \
          -hdr "Accept-Encoding: gzip"
        rxresp -no_obj
        expect resp.status == 200
        expect resp.http.content-length == "100"
        expect resp.http.content-encoding == "<undef>"
        expect resp.http.transfer-encoding == "<undef>"

        # 6. Response status code != 20[0-3]
        txreq -url "/c1.6" \
          -hdr "Accept-Encoding: gzip"
        rxresp
        expect resp.status == 400
        expect resp.http.content-encoding == "<undef>"
        expect resp.http.transfer-encoding == "<undef>"
        expect resp.bodylen == 100

        # 7. Response alerady compressed by the server (with "Accept-Encoding")
        txreq -url "/c1.7" \
          -hdr "Accept-Encoding: gzip"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "something"
        expect resp.http.transfer-encoding == "<undef>"
        expect resp.bodylen == 3
        expect resp.body == "FOO"

        # 8. Response with "Cache-Control: no-transform"
        txreq -url "/c1.8" \
          -hdr "Accept-Encoding: gzip"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "<undef>"
        expect resp.http.transfer-encoding == "<undef>"
        expect resp.http.cache-control == "no-transform"
        expect resp.bodylen == 100

        # 9. Response with uncompressable content-type
        txreq -url "/c1.9" \
          -hdr "Accept-Encoding: gzip"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "<undef>"
        expect resp.http.transfer-encoding == "<undef>"
        expect resp.http.content-type == "text/css"
        expect resp.bodylen == 100

        # 10. Response with uncompressable content-type
        txreq -url "/c1.10" \
          -hdr "Accept-Encoding: gzip"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "<undef>"
        expect resp.http.transfer-encoding == "<undef>"
        expect resp.http.content-type == "multipart/mixed; boundary=\"aaa\""
        expect resp.bodylen == 100
} -run

# GZIP Compression expected (small body)
client c2 -connect ${h1_fe_gzip_sock} {
        # 1. response from the server with a small body with a C-L
        txreq -url "/c2.1" \
          -hdr "Accept-Encoding: gzip"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "gzip"
        expect resp.http.transfer-encoding == "chunked"
        gunzip
        expect resp.bodylen == 100

        # 2. response from the server with a small chunked body
        txreq -url "/c2.2" \
          -hdr "Accept-Encoding: gzip"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "gzip"
        expect resp.http.transfer-encoding == "chunked"
        gunzip
        expect resp.bodylen == 609
} -run

# Identity compression expect (Huge body)
# Identity is used because of a limitation of vtest (the uncompressed body size
# must be lower than 10 times of the compressed one)
client c3 -connect ${h1_fe_identity_sock} {
        # 1. response from the server with a huge body with a C-L
        txreq -url "/c3.1"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "<undef>"
        expect resp.http.transfer-encoding == "chunked"
        expect resp.bodylen == 50000

        # 2. response from the server with a huge chunked body
        txreq -url "/c3.2"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "<undef>"
        expect resp.http.transfer-encoding == "chunked"
        expect resp.bodylen == 50000
} -run


# Compression expected with priority
client c4 -connect ${h1_fe_gzip_deflate_sock} {
        # 1. response from the server with a small body with a C-L
        txreq -url "/c4.1" \
          -hdr "Accept-Encoding: *;q=0, gzip;q=0.750, deflate;q=0.500"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "gzip"
        expect resp.http.transfer-encoding == "chunked"

        # 2. response from the server with a small body with a C-L
        txreq -url "/c4.2" \
          -hdr "Accept-Encoding: *;q=0, gzip;q=0.500, deflate;q=0.750"
        rxresp
        expect resp.status == 200
        expect resp.http.content-encoding == "deflate"
        expect resp.http.transfer-encoding == "chunked"
} -run