-
-
Save mnot/74ba8ed638a3d85659aa2868b9240d50 to your computer and use it in GitHub Desktop.
Implementing the Cache-Status header field in VCL (WIP)
This file contains 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
declare local var.cache_status STRING; | |
declare local var.cache_status_visible BOOL; | |
set var.cache_status = server.identity; | |
set var.cache_status_visible = true; | |
if (fastly_info.state ~ "^NONE") { | |
set var.cache_status_visible = false; | |
} | |
elsif (fastly_info.state ~ "^HIT-SYNTH-") { | |
set var.cache_status_visible = false; | |
} | |
elsif (fastly_info.state ~ "^(PASS|HITPASS)-") { | |
set var.cache_status = var.cache_status ";fwd=bypass"; | |
} | |
elsif (fastly_info.state ~ "^HIT") { | |
set var.cache_status = var.cache_status ";hit"; | |
} | |
elsif (fastly_info.state ~ "^MISS-") { | |
if (stale.exists) { | |
set var.cache_status = var.cache_status ";fwd=stale"; | |
} else { | |
set var.cache_status = var.cache_status ";fwd=miss"; | |
} | |
} | |
else { | |
set var.cache_status_visible = false; | |
} | |
if (fastly_info.state ~ "-REFRESH") { | |
set var.cache_status = var.cache_status ";fwd=stale;fwd-status=304"; | |
} | |
if (req.http.tmp-ttl) { | |
set var.cache_status = var.cache_status ";ttl=" regsub(req.http.tmp-ttl, "\..*$", ""); | |
unset req.http.tmp-ttl; | |
} | |
if (fastly_info.state ~ "-WAIT") { | |
set var.cache_status = var.cache_status ";collapsed"; | |
} | |
if (var.cache_status_visible) { | |
if (!resp.http.Cache-Status) { | |
set resp.http.Cache-Status = var.cache_status; | |
} else { | |
set resp.http.Cache-Status = resp.http.Cache-Status ", " var.cache_status; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment