|
| 1 | +varnishtest "Compression handling" |
| 2 | + |
| 3 | +server s1 { |
| 4 | + # first request will be the probe, handle it and be on our way |
| 5 | + rxreq |
| 6 | + expect req.url == "/health_check.php" |
| 7 | + txresp |
| 8 | + |
| 9 | + # the probe expects the connection to close |
| 10 | + close |
| 11 | + accept |
| 12 | + |
| 13 | + # reply with a 200 |
| 14 | + loop 4 { |
| 15 | + rxreq |
| 16 | + txresp -hdr "answer-to: POST" |
| 17 | + } |
| 18 | + |
| 19 | + rxreq |
| 20 | + txresp -hdr "answer-to: GET" |
| 21 | +} -start |
| 22 | + |
| 23 | +# generate usable VCL pointing towards s1 |
| 24 | +# mostly, we replace the place-holders, but we also jack up the probe |
| 25 | +# interval to avoid further interference |
| 26 | +shell { |
| 27 | + # testdir is automatically set to the directory containing the present vtc |
| 28 | + sed ${testdir}/../../../app/code/Magento/PageCache/etc/varnish6.vcl > ${tmpdir}/output.vcl \ |
| 29 | + -e 's@\.interval = 5s;@.interval = 5m; .initial = 10;@' \ |
| 30 | + -e 's@/\* {{ host }} \*/@${s1_addr}@' \ |
| 31 | + -e 's@/\* {{ port }} \*/@${s1_port}@' \ |
| 32 | + -e 's@/\* {{ ssl_offloaded_header }} \*/@unused@' \ |
| 33 | + -e 's@/\* {{ grace_period }} \*/@0@' |
| 34 | +} |
| 35 | + |
| 36 | +# little trick here: we leverage the fact that subroutines with the same name |
| 37 | +# are concatenated in the order they are seen. This allows us to tweak the |
| 38 | +# backend response before the official VCL processes it, so we can tell |
| 39 | +# client c1 which AE header was sent to the backend |
| 40 | +varnish v1 -vcl { |
| 41 | + sub vcl_backend_response { |
| 42 | + set beresp.http.sent-accept-encoding = bereq.http.accept-encoding; |
| 43 | + } |
| 44 | + include "${tmpdir}/output.vcl"; |
| 45 | +}-start |
| 46 | + |
| 47 | +# make sur ethe probe request fired |
| 48 | +delay 1 |
| 49 | + |
| 50 | +client c1 { |
| 51 | + # Uncacheable (it's a POST), Varnish should send it verbatim to s1 |
| 52 | + txreq -method "POST" -hdr "accept-encoding: something completely random" |
| 53 | + rxresp |
| 54 | + expect resp.http.sent-accept-encoding == "something completely random" |
| 55 | + |
| 56 | + # cacheable GET |
| 57 | + txreq -hdr "accept-encoding: will be overridden" |
| 58 | + rxresp |
| 59 | + expect resp.http.sent-accept-encoding == "gzip" |
| 60 | + |
| 61 | + # same thing, but the extension suggest an already compressed response |
| 62 | + txreq -url "/foo.tgz" -hdr "accept-encoding: will be overridden" |
| 63 | + rxresp |
| 64 | + expect resp.http.sent-accept-encoding == "gzip" |
| 65 | +} -run |
0 commit comments