Last active
July 19, 2017 16:11
-
-
Save rezan/292965f338f5f221e50d310326ecd6f8 to your computer and use it in GitHub Desktop.
A simplified version of a multi tier response pipeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vcl 6.0; | |
# Logic for passing response objects thru a distributed VCL architecture | |
import std; | |
sub vcl_backend_response | |
{ | |
if (beresp.http.X-DVCL-ttl) { | |
set beresp.ttl = std.duration(beresp.http.X-DVCL-ttl, 0s); | |
set beresp.grace = std.duration(beresp.http.X-DVCL-grace, 0s); | |
set beresp.keep = std.duration(beresp.http.X-DVCL-keep, 0s); | |
if (beresp.http.X-DVCL-uncacheable == "true") { | |
set beresp.uncacheable = true; | |
} | |
return(deliver); | |
} | |
# Fallthru to native vcl_backend_response and calculate beresp.ttl/grace/keep/uncacheable | |
# Catch values in vcl_deliver | |
} | |
# vcl_hit or vcl_backend_response will enter here | |
sub vcl_deliver | |
{ | |
set resp.http.X-DVCL-ttl = obj.ttl + "s"; | |
set resp.http.X-DVCL-grace = obj.grace + "s"; | |
set resp.http.X-DVCL-keep = obj.keep + "s"; | |
set resp.http.X-DVCL-uncacheable = obj.uncacheable; | |
set resp.http.X-DVCL-total-hits = std.integer(set resp.http.X-DVCL-hits, 0) + obj.hits; | |
set resp.http.X-DVCL-hits = obj.hits; | |
unset resp.http.X-Varnish; | |
unset resp.http.Via; | |
# Return object to the next tier, vcl_deliver will run on Edge | |
return(deliver); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment