Skip to content

Commit

Permalink
Adapt surrogate keys only on outermost Fastly node
Browse files Browse the repository at this point in the history
  • Loading branch information
herzog31 committed Dec 19, 2024
1 parent 2575af9 commit 60c5081
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions etc/vcl_snippets/fetch.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,29 @@
if (beresp.ttl > 0s && (req.request == "GET" || req.request == "HEAD") && !req.http.x-pass ) {
unset beresp.http.set-cookie;

# init surrogate keys
if (beresp.http.X-Magento-Tags) {
if (beresp.http.Surrogate-Key) {
set beresp.http.Surrogate-Key = beresp.http.Surrogate-Key " " beresp.http.X-Magento-Tags " text";
# init surrogate keys if on outermost node
if (fastly.ff.visits_this_service == 0) {
if (beresp.http.X-Magento-Tags) {
if (beresp.http.Surrogate-Key) {
set beresp.http.Surrogate-Key = beresp.http.Surrogate-Key " " beresp.http.X-Magento-Tags " text";
} else {
set beresp.http.Surrogate-Key = beresp.http.X-Magento-Tags " text";
}
} else {
set beresp.http.Surrogate-Key = beresp.http.X-Magento-Tags " text";
if (beresp.http.Surrogate-Key) {
set beresp.http.Surrogate-Key = beresp.http.Surrogate-Key " text";
} else {
set beresp.http.Surrogate-Key = "text";
}
}
} else {
if (beresp.http.Surrogate-Key) {
set beresp.http.Surrogate-Key = beresp.http.Surrogate-Key " text";
} else {
set beresp.http.Surrogate-Key = "text";
}
}

# set surrogate keys by content type if they are image/script or CSS
if (beresp.http.Content-Type ~ "(image|script|css)") {
if (beresp.http.Surrogate-Key) {
set beresp.http.Surrogate-Key = beresp.http.Surrogate-Key " " re.group.1;
} else {
set beresp.http.Surrogate-Key = re.group.1;
# set surrogate keys by content type if they are image/script or CSS
if (beresp.http.Content-Type ~ "(image|script|css)") {
if (beresp.http.Surrogate-Key) {
set beresp.http.Surrogate-Key = beresp.http.Surrogate-Key " " re.group.1;
} else {
set beresp.http.Surrogate-Key = re.group.1;
}
}
}
}
Expand Down

0 comments on commit 60c5081

Please sign in to comment.