Skip to content

Commit 795942b

Browse files
Indrani SonawaneIndrani Sonawane
authored andcommitted
Merge remote-tracking branch '38211/no_compression' into 247beta3_jan
2 parents a01560a + 85c8b52 commit 795942b

File tree

4 files changed

+66
-45
lines changed

4 files changed

+66
-45
lines changed

app/code/Magento/PageCache/etc/varnish4.vcl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,6 @@ sub vcl_recv {
7676
# collect all cookies
7777
std.collect(req.http.Cookie);
7878

79-
# Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression
80-
if (req.http.Accept-Encoding) {
81-
if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
82-
# No point in compressing these
83-
unset req.http.Accept-Encoding;
84-
} elsif (req.http.Accept-Encoding ~ "gzip") {
85-
set req.http.Accept-Encoding = "gzip";
86-
} elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
87-
set req.http.Accept-Encoding = "deflate";
88-
} else {
89-
# unknown algorithm
90-
unset req.http.Accept-Encoding;
91-
}
92-
}
93-
9479
# Remove all marketing get parameters to minimize the cache objects
9580
if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
9681
set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");

app/code/Magento/PageCache/etc/varnish5.vcl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,6 @@ sub vcl_recv {
7777
# collect all cookies
7878
std.collect(req.http.Cookie);
7979

80-
# Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression
81-
if (req.http.Accept-Encoding) {
82-
if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
83-
# No point in compressing these
84-
unset req.http.Accept-Encoding;
85-
} elsif (req.http.Accept-Encoding ~ "gzip") {
86-
set req.http.Accept-Encoding = "gzip";
87-
} elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
88-
set req.http.Accept-Encoding = "deflate";
89-
} else {
90-
# unknown algorithm
91-
unset req.http.Accept-Encoding;
92-
}
93-
}
94-
9580
# Remove all marketing get parameters to minimize the cache objects
9681
if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
9782
set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");

app/code/Magento/PageCache/etc/varnish6.vcl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,6 @@ sub vcl_recv {
8181
# collect all cookies
8282
std.collect(req.http.Cookie);
8383

84-
# Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression
85-
if (req.http.Accept-Encoding) {
86-
if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
87-
# No point in compressing these
88-
unset req.http.Accept-Encoding;
89-
} elsif (req.http.Accept-Encoding ~ "gzip") {
90-
set req.http.Accept-Encoding = "gzip";
91-
} elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
92-
set req.http.Accept-Encoding = "deflate";
93-
} else {
94-
# unknown algorithm
95-
unset req.http.Accept-Encoding;
96-
}
97-
}
98-
9984
# Remove all marketing get parameters to minimize the cache objects
10085
if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
10186
set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");

dev/tests/varnish/compression.vtc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 \
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+
${testdir}/../../../app/code/Magento/PageCache/etc/varnish6.vcl > ${tmpdir}/output.vcl
35+
}
36+
37+
# little trick here: we leverage the fact that subroutines with the same name
38+
# are concatenated in the order they are seen. This allows us to tweak the
39+
# backend response before the official VCL processes it, so we can tell
40+
# client c1 which AE header was sent to the backend
41+
varnish v1 -vcl {
42+
sub vcl_backend_response {
43+
set beresp.http.sent-accept-encoding = bereq.http.accept-encoding;
44+
}
45+
include "${tmpdir}/output.vcl";
46+
}-start
47+
48+
# make sur ethe probe request fired
49+
delay 1
50+
51+
client c1 {
52+
# Uncacheable (it's a POST), Varnish should send it verbatim to s1
53+
txreq -method "POST" -hdr "accept-encoding: something completely random"
54+
rxresp
55+
expect resp.http.sent-accept-encoding == "something completely random"
56+
57+
# cacheable GET
58+
txreq -hdr "accept-encoding: will be overridden"
59+
rxresp
60+
expect resp.http.sent-accept-encoding == "gzip"
61+
62+
# same thing, but the extension suggest an already compressed response
63+
txreq -url "/foo.tgz" -hdr "accept-encoding: will be overridden"
64+
rxresp
65+
expect resp.http.sent-accept-encoding == "gzip"
66+
} -run

0 commit comments

Comments
 (0)