Unverified Commit 7d2e14df authored by Dridi Boukelmoune's avatar Dridi Boukelmoune Committed by Nils Goroll

builtin: Split vcl_backend_response too

It's one more indirection than vcl_recv because the same logic applies
to multiple cases, so we first have subs for the different conditions
and they all call the shared vcl_beresp_hitmiss sub.

The vcl_beresp_hitmiss sub returns on purpose, that doesn't change the
default VCL behavior and makes it more usable from VCL code:

    if (some user condition applies) {
            call vcl_beresp_hitmiss;
    }

No need to force all call sites to return(deliver) when the desired
outcome is explicit. Extracting this sub also enables VCL authors to
only tweak the hitmiss TTL in one place.

For better compliance, we might also introduce a vcl_beresp_hitpass sub
for some of the built-in cases where a hit-for-miss object might be less
appropriate. The compliance effort will however change some semantics
and is outside of the scope of this split.
parent 90127a47
......@@ -168,16 +168,42 @@ sub vcl_backend_response {
if (bereq.uncacheable) {
return (deliver);
}
if (beresp.ttl <= 0s ||
beresp.http.Set-Cookie ||
beresp.http.Surrogate-control ~ "(?i)no-store" ||
call vcl_beresp_stale;
call vcl_beresp_cookie;
call vcl_beresp_control;
call vcl_beresp_vary;
return (deliver);
}
sub vcl_beresp_stale {
if (beresp.ttl <= 0s) {
call vcl_beresp_hitmiss;
}
}
sub vcl_beresp_cookie {
if (beresp.http.Set-Cookie) {
call vcl_beresp_hitmiss;
}
}
sub vcl_beresp_control {
if (beresp.http.Surrogate-control ~ "(?i)no-store" ||
(!beresp.http.Surrogate-Control &&
beresp.http.Cache-Control ~ "(?i:no-cache|no-store|private)") ||
beresp.http.Vary == "*") {
# Mark as "Hit-For-Miss" for the next 2 minutes
set beresp.ttl = 120s;
set beresp.uncacheable = true;
beresp.http.Cache-Control ~ "(?i:no-cache|no-store|private)")) {
call vcl_beresp_hitmiss;
}
}
sub vcl_beresp_vary {
if (beresp.http.Vary == "*") {
call vcl_beresp_hitmiss;
}
}
sub vcl_beresp_hitmiss {
set beresp.ttl = 120s;
set beresp.uncacheable = true;
return (deliver);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment