[master] 00b190a0a Define (be)?req.filters fields and adjust VRT
Nils Goroll
nils.goroll at uplex.de
Mon Sep 30 14:19:07 UTC 2024
commit 00b190a0aed482a638fdb9f1207598cca3db6c27
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Dec 11 08:00:35 2023 +0100
Define (be)?req.filters fields and adjust VRT
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 9c40faffb..b52cbab01 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -394,8 +394,11 @@ struct busyobj {
struct sess *sp;
struct worker *wrk;
+ /* beresp.body */
struct vfp_ctx *vfc;
const char *vfp_filter_list;
+ /* bereq.body */
+ const char *vdp_filter_list;
struct ws ws[1];
uintptr_t ws_bo;
@@ -537,9 +540,11 @@ struct req {
struct objcore *objcore;
struct objcore *stale_oc;
- /* Deliver pipeline */
+ /* resp.body */
struct vdp_ctx *vdc;
const char *vdp_filter_list;
+ /* req.body */
+ const char *vfp_filter_list;
/* Transaction VSL buffer */
struct vsl_log vsl[1];
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index c5f4788a3..eef6cb527 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -377,6 +377,10 @@ pan_busyobj(struct vsb *vsb, const struct busyobj *bo)
VSB_printf(vsb, "vfp_filter_list = \"%s\",\n",
bo->vfp_filter_list);
}
+ if (bo->vdp_filter_list != NULL) {
+ VSB_printf(vsb, "vdp_filter_list = \"%s\",\n",
+ bo->vdp_filter_list);
+ }
WS_Panic(vsb, bo->ws);
VSB_printf(vsb, "ws_bo = %p,\n", (void *)bo->ws_bo);
@@ -464,6 +468,15 @@ pan_req(struct vsb *vsb, const struct req *req)
else
VSB_printf(vsb, "step = %s\n", req->req_step->name);
+ if (req->vfp_filter_list != NULL) {
+ VSB_printf(vsb, "vfp_filter_list = \"%s\",\n",
+ req->vfp_filter_list);
+ }
+ if (req->vdp_filter_list != NULL) {
+ VSB_printf(vsb, "vdp_filter_list = \"%s\",\n",
+ req->vdp_filter_list);
+ }
+
VSB_printf(vsb, "req_body = %s,\n",
req->req_body_status ? req->req_body_status->name : "NULL");
diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c
index a9c20250d..42e2b93b0 100644
--- a/bin/varnishd/cache/cache_req.c
+++ b/bin/varnishd/cache/cache_req.c
@@ -252,6 +252,7 @@ Req_Rollback(VRT_CTX)
VCL_TaskEnter(req->top->privs);
HTTP_Clone(req->http, req->http0);
req->vdp_filter_list = NULL;
+ req->vfp_filter_list = NULL;
req->vcf = NULL;
if (WS_Overflowed(req->ws))
req->wrk->stats->ws_client_overflow++;
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 20e4eb13b..9dfebfd99 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -909,6 +909,8 @@ cnt_recv_prep(struct req *req, const char *ci)
req->is_hitpass = 0;
req->err_code = 0;
req->err_reason = NULL;
+
+ req->vfp_filter_list = NULL;
}
/*--------------------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_vrt_filter.c b/bin/varnishd/cache/cache_vrt_filter.c
index 4d777d464..707533eea 100644
--- a/bin/varnishd/cache/cache_vrt_filter.c
+++ b/bin/varnishd/cache/cache_vrt_filter.c
@@ -400,6 +400,14 @@ VBF_Get_Filter_List(struct busyobj *bo)
return (filter_on_ws(bo->ws, vbf_default_filter_list, bo));
}
+static const char *
+bereq_Empty_Filter(struct busyobj *bo)
+{
+
+ (void)bo;
+ return ("");
+}
+
/*--------------------------------------------------------------------
*/
@@ -433,9 +441,25 @@ resp_Get_Filter_List(struct req *req)
return (filter_on_ws(req->ws, resp_default_filter_list, req));
}
+static const char *
+req_Empty_Filter(struct req *req)
+{
+
+ (void)req;
+ return ("");
+}
+
+/*--------------------------------------------------------------------*/
+static int
+req_filter_can(struct req *req) {
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+
+ return (req->req_body_status->avail == 1);
+}
+
/*--------------------------------------------------------------------*/
-#define FILTER_VAR(vcl, in, func, fld) \
+#define FILTER_VAR(vcl, in, func, cond, fld) \
VCL_STRING \
VRT_r_##vcl##_filters(VRT_CTX) \
{ \
@@ -453,6 +477,10 @@ resp_Get_Filter_List(struct req *req)
\
(void)str; \
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
+ if (! (cond)) { \
+ VRT_fail(ctx, #vcl ".filters not settable"); \
+ return; \
+ } \
b = VRT_StrandsWS(ctx->in->ws, str, s); \
if (b == NULL) \
WS_MarkOverflow(ctx->in->ws); \
@@ -460,5 +488,7 @@ resp_Get_Filter_List(struct req *req)
ctx->in->fld = b; \
}
-FILTER_VAR(beresp, bo, VBF_Get_Filter_List, vfp_filter_list)
-FILTER_VAR(resp, req, resp_Get_Filter_List, vdp_filter_list)
+FILTER_VAR(bereq, bo, bereq_Empty_Filter, 1, vdp_filter_list)
+FILTER_VAR(beresp, bo, VBF_Get_Filter_List, 1, vfp_filter_list)
+FILTER_VAR(req, req, req_Empty_Filter, req_filter_can(ctx->req), vfp_filter_list)
+FILTER_VAR(resp, req, resp_Get_Filter_List, 1, vdp_filter_list)
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index e895753b2..86b5e4955 100644
--- a/doc/sphinx/reference/vcl_var.rst
+++ b/doc/sphinx/reference/vcl_var.rst
@@ -236,6 +236,32 @@ req.esi_level
A count of how many levels of ESI requests we're currently at.
+.. _req.filters:
+
+req.filters
+
+ Type: STRING
+
+ Readable from: vcl_recv
+
+ Writable from: vcl_recv
+
+ List of Varnish Fetch Processor (VFP) filters the req.body
+ will be pulled through. The order left to right signifies
+ processing from client to cache, iow the leftmost filter is
+ run first on the body as received from the client after
+ decoding of any transfer encodings.
+
+ VFP Filters change the body before potentially being cached
+ (e.g. using ``std.cache_req.body()``) and/or being handled by
+ the backend side, where it may get processed again by
+ bereq.filters.
+
+ Trying to set req.filters after processing the request body
+ (again, for example with ``std.cache_req.body()``) triggers a
+ VCL error.
+
+
.. _req.grace:
req.grace
@@ -694,6 +720,20 @@ bereq.connect_timeout
established.
+.. _bereq.filters:
+
+bereq.filters
+
+ Type: STRING
+
+ Readable from: vcl_backend_fetch
+
+ Writable from: vcl_backend_fetch
+
+ List of VDP filters the bereq.body will be pushed through when
+ sending the body to the backend.
+
+
.. _bereq.first_byte_timeout:
bereq.first_byte_timeout
More information about the varnish-commit
mailing list