[master] 7d2e14dff builtin: Split vcl_backend_response too

Nils Goroll nils.goroll at uplex.de
Wed Mar 3 10:15:04 UTC 2021


commit 7d2e14dff7dc3761e596113c78e6551a721ef7de
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Jan 26 11:32:12 2021 +0100

    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.

diff --git a/bin/varnishd/builtin.vcl b/bin/varnishd/builtin.vcl
index 96aeb6474..eb7c9272a 100644
--- a/bin/varnishd/builtin.vcl
+++ b/bin/varnishd/builtin.vcl
@@ -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);
 }
 


More information about the varnish-commit mailing list