[master] 61f2841df vcl: add unset req.grace and unset req.ttl
Nils Goroll
nils.goroll at uplex.de
Thu Nov 7 18:07:06 UTC 2024
commit 61f2841df6b8ff6767615cf08565f71dced09ae1
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Thu Nov 7 18:38:32 2024 +0100
vcl: add unset req.grace and unset req.ttl
There was no way to reset these from VCL to the "unset" value of -1.
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 60409beca..f0726cc81 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -576,12 +576,24 @@ VRT_r_req_##nm(VRT_CTX) \
return (ctx->req->elem); \
}
+#define REQ_VAR_U(nm, elem, val) \
+ \
+VCL_VOID \
+VRT_u_req_##nm(VRT_CTX) \
+{ \
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
+ CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); \
+ ctx->req->elem = val; \
+}
+
REQ_VAR_R(backend_hint, director_hint, VCL_BACKEND)
REQ_VAR_L(ttl, d_ttl, VCL_DURATION, if (!(arg>0.0)) arg = 0;)
REQ_VAR_R(ttl, d_ttl, VCL_DURATION)
+REQ_VAR_U(ttl, d_ttl, -1)
REQ_VAR_L(grace, d_grace, VCL_DURATION, if (!(arg>0.0)) arg = 0;)
REQ_VAR_R(grace, d_grace, VCL_DURATION)
+REQ_VAR_U(grace, d_grace, -1)
VCL_VOID
VRT_l_req_backend_hint(VRT_CTX, VCL_BACKEND be)
diff --git a/bin/varnishtest/tests/b00064.vtc b/bin/varnishtest/tests/b00064.vtc
index 47271831b..73c7d2dff 100644
--- a/bin/varnishtest/tests/b00064.vtc
+++ b/bin/varnishtest/tests/b00064.vtc
@@ -33,6 +33,10 @@ varnish v1 -vcl+backend {
if (req.http.X-no-grace) {
set req.grace = 0s;
}
+ if (req.http.X-but-grace) {
+ unset req.grace;
+ }
+ set req.http.req-grace = req.grace;
}
sub vcl_hit {
set req.http.X-grace = obj.grace;
@@ -106,12 +110,11 @@ client c3 {
delay .1
-# c4 does not disable grace, and should get the grace object even
-# though c3 is waiting on the background thread to deliver a new
-# version.
+# c4 unsets req.grace after sessing it and should get the grace object even
+# though c3 is waiting on the background thread to deliver a new version.
client c4 {
- txreq
+ txreq -hdr "X-no-grace: true" -hdr "X-but-grace: true"
rxresp
barrier b1 sync
expect resp.status == 200
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index aff4dd323..450c64fc7 100644
--- a/doc/sphinx/reference/vcl_var.rst
+++ b/doc/sphinx/reference/vcl_var.rst
@@ -272,12 +272,15 @@ req.grace
Writable from: client
+ Unsettable from: client
Upper limit on the object grace.
During lookup the minimum of req.grace and the object's stored
grace value will be used as the object's grace.
+ When reading the unset value, it is returned as -1.
+
.. _req.hash:
@@ -536,9 +539,12 @@ req.ttl
Writable from: client
+ Unsettable from: client
+
Upper limit on the object age for cache lookups to return hit.
+ When reading the unset value, it is returned as -1.
.. _req.url:
More information about the varnish-commit
mailing list