Skip to content

Instantly share code, notes, and snippets.

@mnot
Created Jul 16, 2020
Embed
What would you like to do?
Implementing the Cache-Status header field in VCL (WIP)
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