]> git.sesse.net Git - remoteglot/commitdiff
Prepare the VCL for multiple backends, with independent cache management.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 21 Jun 2015 22:40:05 +0000 (00:40 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 21 Jun 2015 22:40:05 +0000 (00:40 +0200)
default.vcl

index 38631cb4f1d3c6f399dd4fb1378dec993339aa32..aa2585f56cd0a152350bd631a82bc9145dadc304 100644 (file)
@@ -2,6 +2,7 @@
 
 vcl 4.0;
 
 
 vcl 4.0;
 
+# You can have multiple ones; see vcl_recv.
 backend analysis {
     .host = "127.0.0.1";
     .port = "5000";
 backend analysis {
     .host = "127.0.0.1";
     .port = "5000";
@@ -18,8 +19,12 @@ sub vcl_recv {
     }
     if (req.http.host ~ "analysis\.sesse\.net$" && req.url ~ "^/analysis\.pl") {
         set req.backend_hint = analysis;
     }
     if (req.http.host ~ "analysis\.sesse\.net$" && req.url ~ "^/analysis\.pl") {
         set req.backend_hint = analysis;
+        # Ignored by the backend; just to identify it in vcl_backend_response.
+        set req.http.x-analysis-backend = "backend1";
         return (hash);
     }
         return (hash);
     }
+    # You can check on e.g. /analysis2\.pl here if you have multiple
+    # backends; just remember to set x-analysis-backend to something unique.
 }
 
 sub vcl_deliver { 
 }
 
 sub vcl_deliver { 
@@ -31,6 +36,7 @@ sub vcl_deliver {
         unset resp.http.X-Powered-By;
     }
     unset resp.http.x-analysis;
         unset resp.http.X-Powered-By;
     }
     unset resp.http.x-analysis;
+    unset resp.http.x-analysis-backend;
 }
 
 sub vcl_hash {
 }
 
 sub vcl_hash {
@@ -51,7 +57,10 @@ sub vcl_backend_response {
         }
         if (beresp.http.content-type ~ "json") {
              set beresp.http.x-analysis = 1;
         }
         if (beresp.http.content-type ~ "json") {
              set beresp.http.x-analysis = 1;
-             ban ( "obj.http.x-analysis == 1 && obj.http.x-rglm != " + beresp.http.x-rglm );
+             set beresp.http.x-analysis-backend = bereq.http.x-analysis-backend;
+             ban ( "obj.http.x-analysis == 1 && " +
+                   "obj.http.x-analysis-backend == " + bereq.http.x-analysis-backend + " && " +
+                   "obj.http.x-rglm != " + beresp.http.x-rglm );
         }
         return (deliver);
     }
         }
         return (deliver);
     }