[master] 95dfe7f04 Add VCL design pattern about resp.status and modulus operator.

Poul-Henning Kamp phk at FreeBSD.org
Tue Feb 16 14:16:06 UTC 2021


commit 95dfe7f04528133d67d5cc6839c81e8092aab504
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Feb 16 14:14:33 2021 +0000

    Add VCL design pattern about resp.status and modulus operator.

diff --git a/doc/sphinx/reference/dp_vcl_resp_status.rst b/doc/sphinx/reference/dp_vcl_resp_status.rst
new file mode 100644
index 000000000..a4edb17a5
--- /dev/null
+++ b/doc/sphinx/reference/dp_vcl_resp_status.rst
@@ -0,0 +1,22 @@
+.. _dp_vcl_resp_status:
+
+Using extra digits in resp.status 
+=================================
+
+In Varnish the ``.status`` variables can hold more than three
+digits, which is useful to send information to ``vcl_synth{}``
+about which error message to produce::
+
+    sub vcl_recv {
+       if ([...]) {
+           return(synth(12404));
+       }
+    }
+
+    sub vcl_synth {
+        if (resp.status == 12404) {
+            [...]       // this specific 404
+        } else if (resp.status % 1000 == 404) {
+            [...]       // all other 404's
+        }
+    }
diff --git a/doc/sphinx/reference/index.rst b/doc/sphinx/reference/index.rst
index e7ff6c9e0..58f6f7a93 100644
--- a/doc/sphinx/reference/index.rst
+++ b/doc/sphinx/reference/index.rst
@@ -23,6 +23,7 @@ VCL Design Patterns
 	:maxdepth: 1
 
 	dp_vcl_recv_hash.rst
+	dp_vcl_resp_status.rst
 
 Bundled VMODs
 -------------


More information about the varnish-commit mailing list