Christopher Faulet | e98ce25 | 2018-12-21 15:24:57 +0100 | [diff] [blame] | 1 | varnishtest "Basic compression test" |
| 2 | |
| 3 | #REQUIRE_VERSION=1.9 |
| 4 | #REQUIRE_OPTION=ZLIB|SLZ |
| 5 | |
| 6 | feature ignore_unknown_macro |
| 7 | |
| 8 | server 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 | |
| 180 | haproxy h1 -conf { |
| 181 | defaults |
| 182 | mode http |
| 183 | ${no-htx} option http-use-htx |
| 184 | timeout connect 1s |
| 185 | timeout client 1s |
| 186 | timeout server 1s |
| 187 | |
| 188 | frontend fe-gzip |
| 189 | bind "fd@${fe_gzip}" |
| 190 | default_backend be-gzip |
| 191 | |
| 192 | frontend fe-identity |
| 193 | bind "fd@${fe_identity}" |
| 194 | default_backend be-identity |
| 195 | |
| 196 | frontend fe-gzip-deflate |
| 197 | bind "fd@${fe_gzip_deflate}" |
| 198 | default_backend be-gzip-defalte |
| 199 | |
| 200 | backend be-gzip |
| 201 | compression algo gzip |
| 202 | compression type text/html text/plain |
| 203 | server www ${s1_addr}:${s1_port} |
| 204 | |
| 205 | backend be-identity |
| 206 | compression algo identity |
| 207 | server www ${s1_addr}:${s1_port} |
| 208 | |
| 209 | backend be-gzip-defalte |
| 210 | compression algo gzip deflate |
| 211 | compression offload |
| 212 | server www ${s1_addr}:${s1_port} |
| 213 | |
| 214 | } -start |
| 215 | |
| 216 | # No compression expected because not supported by the client or because |
| 217 | # something in the request or response headers forbids it. |
| 218 | client c1 -connect ${h1_fe_gzip_sock} { |
| 219 | # 1. no "Accept-Encoding header" |
| 220 | txreq -url "/c1.1" |
| 221 | rxresp |
| 222 | expect resp.status == 200 |
| 223 | expect resp.http.content-encoding == "<undef>" |
| 224 | expect resp.http.transfer-encoding == "<undef>" |
| 225 | expect resp.bodylen == 100 |
| 226 | |
| 227 | # 2. Buggy User-Agent |
| 228 | txreq -url "/c1.2" \ |
| 229 | -hdr "Accept-Encoding: gzip" \ |
| 230 | -hdr "User-Agent: Mozilla/4" |
| 231 | rxresp |
| 232 | expect resp.status == 200 |
| 233 | expect resp.http.content-encoding == "<undef>" |
| 234 | expect resp.http.transfer-encoding == "<undef>" |
| 235 | expect resp.bodylen == 100 |
| 236 | |
| 237 | # 3. HTTP/1.0 request |
| 238 | txreq -url "/c1.3" \ |
| 239 | -proto "HTTP/1.0" \ |
| 240 | -hdr "Accept-Encoding: gzip" \ |
| 241 | -hdr "Connection: keep-alive" |
| 242 | rxresp |
| 243 | expect resp.status == 200 |
| 244 | expect resp.http.content-encoding == "<undef>" |
| 245 | expect resp.http.transfer-encoding == "<undef>" |
| 246 | expect resp.bodylen == 100 |
| 247 | |
| 248 | # 4. HTTP/1.0 response |
| 249 | txreq -url "/c1.4" \ |
| 250 | -hdr "Accept-Encoding: gzip" |
| 251 | rxresp |
| 252 | expect resp.status == 200 |
| 253 | expect resp.proto == "HTTP/1.0" |
| 254 | expect resp.http.content-encoding == "<undef>" |
| 255 | expect resp.http.transfer-encoding == "<undef>" |
| 256 | expect resp.bodylen == 100 |
| 257 | |
| 258 | # 5. HEAD method |
| 259 | txreq -req "HEAD" -url "/c1.5" \ |
| 260 | -hdr "Accept-Encoding: gzip" |
| 261 | rxresp -no_obj |
| 262 | expect resp.status == 200 |
| 263 | expect resp.http.content-length == "100" |
| 264 | expect resp.http.content-encoding == "<undef>" |
| 265 | expect resp.http.transfer-encoding == "<undef>" |
| 266 | |
| 267 | # 6. Response status code != 20[0-3] |
| 268 | txreq -url "/c1.6" \ |
| 269 | -hdr "Accept-Encoding: gzip" |
| 270 | rxresp |
| 271 | expect resp.status == 400 |
| 272 | expect resp.http.content-encoding == "<undef>" |
| 273 | expect resp.http.transfer-encoding == "<undef>" |
| 274 | expect resp.bodylen == 100 |
| 275 | |
| 276 | # 7. Response alerady compressed by the server (with "Accept-Encoding") |
| 277 | txreq -url "/c1.7" \ |
| 278 | -hdr "Accept-Encoding: gzip" |
| 279 | rxresp |
| 280 | expect resp.status == 200 |
| 281 | expect resp.http.content-encoding == "something" |
| 282 | expect resp.http.transfer-encoding == "<undef>" |
| 283 | expect resp.bodylen == 3 |
| 284 | expect resp.body == "FOO" |
| 285 | |
| 286 | # 8. Response with "Cache-Control: no-transform" |
| 287 | txreq -url "/c1.8" \ |
| 288 | -hdr "Accept-Encoding: gzip" |
| 289 | rxresp |
| 290 | expect resp.status == 200 |
| 291 | expect resp.http.content-encoding == "<undef>" |
| 292 | expect resp.http.transfer-encoding == "<undef>" |
| 293 | expect resp.http.cache-control == "no-transform" |
| 294 | expect resp.bodylen == 100 |
| 295 | |
| 296 | # 9. Response with uncompressable content-type |
| 297 | txreq -url "/c1.9" \ |
| 298 | -hdr "Accept-Encoding: gzip" |
| 299 | rxresp |
| 300 | expect resp.status == 200 |
| 301 | expect resp.http.content-encoding == "<undef>" |
| 302 | expect resp.http.transfer-encoding == "<undef>" |
| 303 | expect resp.http.content-type == "text/css" |
| 304 | expect resp.bodylen == 100 |
| 305 | |
| 306 | # 10. Response with uncompressable content-type |
| 307 | txreq -url "/c1.10" \ |
| 308 | -hdr "Accept-Encoding: gzip" |
| 309 | rxresp |
| 310 | expect resp.status == 200 |
| 311 | expect resp.http.content-encoding == "<undef>" |
| 312 | expect resp.http.transfer-encoding == "<undef>" |
| 313 | expect resp.http.content-type == "multipart/mixed; boundary=\"aaa\"" |
| 314 | expect resp.bodylen == 100 |
| 315 | } -run |
| 316 | |
| 317 | # GZIP Compression expected (small body) |
| 318 | client c2 -connect ${h1_fe_gzip_sock} { |
| 319 | # 1. response from the server with a small body with a C-L |
| 320 | txreq -url "/c2.1" \ |
| 321 | -hdr "Accept-Encoding: gzip" |
| 322 | rxresp |
| 323 | expect resp.status == 200 |
| 324 | expect resp.http.content-encoding == "gzip" |
| 325 | expect resp.http.transfer-encoding == "chunked" |
| 326 | gunzip |
| 327 | expect resp.bodylen == 100 |
| 328 | |
| 329 | # 2. response from the server with a small chunked body |
| 330 | txreq -url "/c2.2" \ |
| 331 | -hdr "Accept-Encoding: gzip" |
| 332 | rxresp |
| 333 | expect resp.status == 200 |
| 334 | expect resp.http.content-encoding == "gzip" |
| 335 | expect resp.http.transfer-encoding == "chunked" |
| 336 | gunzip |
| 337 | expect resp.bodylen == 609 |
| 338 | } -run |
| 339 | |
| 340 | # Identity compression expect (Huge body) |
| 341 | # Identity is used because of a limitation of vtest (the uncompressed body size |
| 342 | # must be lower than 10 times of the compressed one) |
| 343 | client c3 -connect ${h1_fe_identity_sock} { |
| 344 | # 1. response from the server with a huge body with a C-L |
| 345 | txreq -url "/c3.1" |
| 346 | rxresp |
| 347 | expect resp.status == 200 |
| 348 | expect resp.http.content-encoding == "<undef>" |
| 349 | expect resp.http.transfer-encoding == "chunked" |
| 350 | expect resp.bodylen == 50000 |
| 351 | |
| 352 | # 2. response from the server with a huge chunked body |
| 353 | txreq -url "/c3.2" |
| 354 | rxresp |
| 355 | expect resp.status == 200 |
| 356 | expect resp.http.content-encoding == "<undef>" |
| 357 | expect resp.http.transfer-encoding == "chunked" |
| 358 | expect resp.bodylen == 50000 |
| 359 | } -run |
| 360 | |
| 361 | |
| 362 | # Compression expected with priority |
| 363 | client c4 -connect ${h1_fe_gzip_deflate_sock} { |
| 364 | # 1. response from the server with a small body with a C-L |
| 365 | txreq -url "/c4.1" \ |
| 366 | -hdr "Accept-Encoding: *;q=0, gzip;q=0.750, deflate;q=0.500" |
| 367 | rxresp |
| 368 | expect resp.status == 200 |
| 369 | expect resp.http.content-encoding == "gzip" |
| 370 | expect resp.http.transfer-encoding == "chunked" |
| 371 | |
| 372 | # 2. response from the server with a small body with a C-L |
| 373 | txreq -url "/c4.2" \ |
| 374 | -hdr "Accept-Encoding: *;q=0, gzip;q=0.500, deflate;q=0.750" |
| 375 | rxresp |
| 376 | expect resp.status == 200 |
| 377 | expect resp.http.content-encoding == "deflate" |
| 378 | expect resp.http.transfer-encoding == "chunked" |
| 379 | } -run |