Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
refactor(static): handle ESI changes first
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Apr 25, 2019
1 parent 34c5efe commit 7846b80
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions layouts/fastly/helix.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,15 @@ sub hlx_fetch_static {

sub hlx_deliver_static {
set req.http.X-Trace = req.http.X-Trace + "; hlx_deliver_static";
if (resp.http.X-Static == "Raw/Static" && resp.status == 307) {
elsif (req.http.X-Request-Type == "Static-ESI" && resp.status == 200) {
set req.http.X-Trace = req.http.X-Trace + "(esi)";
# Get the ETag response header and use it to construct a stable URL
declare local var.ext STRING;

set var.ext = ".hlx_" + digest.hash_sha1(resp.http.ETag);
synthetic regsub(req.http.X-Orig-URL, ".esi$", var.ext);
return(deliver);
} elsif (resp.http.X-Static == "Raw/Static" && resp.status == 307) {
# This is done in `vcl_deliver` instead of `vcl_fetch` because of Fastly
# clustering. Changes made to most `req` variables don't make it back to
# the edge node, when `vcl_fetch` is run on a different node.
Expand Down Expand Up @@ -562,14 +570,6 @@ sub hlx_deliver_static {
set req.http.X-Request-Type = "Static";
}
restart;
} elsif (req.http.X-Request-Type == "Static-ESI") {
set req.http.X-Trace = req.http.X-Trace + "(esi)";
# Get the ETag response header and use it to construct a stable URL
declare local var.ext STRING;

set var.ext = ".hlx_" + digest.hash_sha1(resp.http.ETag);
synthetic regsub(req.http.X-Orig-URL, ".esi$", var.ext);
return(deliver);
}
}

Expand Down

0 comments on commit 7846b80

Please sign in to comment.