Skip to content

Commit 4bee161

Browse files
authored
Merge pull request #719 from herzog31/extend-surrogate-keys
Extend surrogate keys instead of replacing them
2 parents a696f66 + 5a8ec02 commit 4bee161

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

Diff for: etc/vcl_snippets/fetch.vcl

+23-9
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,30 @@
106106
if (beresp.ttl > 0s && (req.request == "GET" || req.request == "HEAD") && !req.http.x-pass ) {
107107
unset beresp.http.set-cookie;
108108

109-
# init surrogate keys
110-
if (beresp.http.X-Magento-Tags) {
111-
set beresp.http.Surrogate-Key = beresp.http.X-Magento-Tags " text";
112-
} else {
113-
set beresp.http.Surrogate-Key = "text";
114-
}
109+
# init surrogate keys if on outermost node
110+
if (fastly.ff.visits_this_service == 0 && req.restarts == 0) {
111+
if (beresp.http.X-Magento-Tags) {
112+
if (beresp.http.Surrogate-Key) {
113+
set beresp.http.Surrogate-Key = beresp.http.Surrogate-Key " " beresp.http.X-Magento-Tags " text";
114+
} else {
115+
set beresp.http.Surrogate-Key = beresp.http.X-Magento-Tags " text";
116+
}
117+
} else {
118+
if (beresp.http.Surrogate-Key) {
119+
set beresp.http.Surrogate-Key = beresp.http.Surrogate-Key " text";
120+
} else {
121+
set beresp.http.Surrogate-Key = "text";
122+
}
123+
}
115124

116-
# set surrogate keys by content type if they are image/script or CSS
117-
if (beresp.http.Content-Type ~ "(image|script|css)") {
118-
set beresp.http.Surrogate-Key = re.group.1;
125+
# set surrogate keys by content type if they are image/script or CSS
126+
if (beresp.http.Content-Type ~ "(image|script|css)") {
127+
if (beresp.http.Surrogate-Key) {
128+
set beresp.http.Surrogate-Key = beresp.http.Surrogate-Key " " re.group.1;
129+
} else {
130+
set beresp.http.Surrogate-Key = re.group.1;
131+
}
132+
}
119133
}
120134
}
121135

0 commit comments

Comments
 (0)