[master] 1cae1a455 Add the VRT handling of resp.filter (doesn't do anything yet)

Poul-Henning Kamp phk at FreeBSD.org
Tue Oct 30 07:39:14 UTC 2018


commit 1cae1a455310192f32c72bba8c13a3c1aa8328f5
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Oct 30 07:34:04 2018 +0000

    Add the VRT handling of resp.filter (doesn't do anything yet)

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index a829a43d7..ce39e683d 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -512,6 +512,7 @@ struct req {
 
 	/* Deliver pipeline */
 	struct vdp_ctx		*vdc;
+	const char		*filter_list;
 
 	/* Delivery mode */
 	unsigned		res_mode;
diff --git a/bin/varnishd/cache/cache_vrt_filter.c b/bin/varnishd/cache/cache_vrt_filter.c
index 102b6f710..410d878be 100644
--- a/bin/varnishd/cache/cache_vrt_filter.c
+++ b/bin/varnishd/cache/cache_vrt_filter.c
@@ -285,6 +285,7 @@ VBF_Get_Filter_List(struct busyobj *bo)
 	unsigned u;
 	struct vsb vsb[1];
 
+	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	u = WS_Reserve(bo->ws, 0);
 	if (u == 0) {
 		WS_Release(bo->ws, 0);
@@ -306,34 +307,41 @@ VBF_Get_Filter_List(struct busyobj *bo)
 	return ("");
 }
 
-/*--------------------------------------------------------------------*/
-
-VCL_STRING
-VRT_r_beresp_filters(VRT_CTX)
+static const char *
+resp_Get_Filter_List(struct req *req)
 {
-
-	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
-	if (ctx->bo->filter_list != NULL)
-		return(ctx->bo->filter_list);
-	/* We do not set bo->filter_list yet, things might still change */
-	return (VBF_Get_Filter_List(ctx->bo));
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	return ("");
 }
 
-VCL_VOID
-VRT_l_beresp_filters(VRT_CTX, const char *str, ...)
-{
-	va_list ap;
-	const char *b;
+/*--------------------------------------------------------------------*/
 
-	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
-	va_start(ap, str);
-	b = VRT_String(ctx->bo->ws, NULL, str, ap);
-	va_end(ap);
-	if (b == NULL) {
-		WS_MarkOverflow(ctx->bo->ws);
-		return;
+#define FILTER_VAR(vcl, in, func)					\
+	VCL_STRING							\
+	VRT_r_##vcl##_filters(VRT_CTX)					\
+	{								\
+									\
+		CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);			\
+		if (ctx->in->filter_list != NULL)			\
+			return(ctx->in->filter_list);			\
+		return (func(ctx->in));					\
+	}								\
+									\
+	VCL_VOID							\
+	VRT_l_##vcl##_filters(VRT_CTX, const char *str, ...)		\
+	{								\
+		va_list ap;						\
+		const char *b;						\
+									\
+		CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);			\
+		va_start(ap, str);					\
+		b = VRT_String(ctx->in->ws, NULL, str, ap);		\
+		va_end(ap);						\
+		if (b == NULL)						\
+			WS_MarkOverflow(ctx->in->ws);			\
+		else							\
+			ctx->in->filter_list = b;			\
 	}
-	ctx->bo->filter_list = b;
-}
+
+FILTER_VAR(beresp, bo, VBF_Get_Filter_List)
+FILTER_VAR(resp, req, resp_Get_Filter_List)
diff --git a/bin/varnishtest/tests/g00003.vtc b/bin/varnishtest/tests/g00003.vtc
index 74bfa5814..773917cba 100644
--- a/bin/varnishtest/tests/g00003.vtc
+++ b/bin/varnishtest/tests/g00003.vtc
@@ -46,6 +46,10 @@ varnish v1 -cliok "param.set http_gzip_support true" -vcl+backend {
 			set beresp.filters = "gzip gunzip gzip gunzip gzip";
 		}
 	}
+	sub vcl_deliver {
+		set resp.http.filters = resp.filters;
+		set resp.filters = "";
+	}
 } -start
 
 client c1 {
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index 054cf2ff4..b269aa029 100644
--- a/doc/sphinx/reference/vcl_var.rst
+++ b/doc/sphinx/reference/vcl_var.rst
@@ -1147,6 +1147,15 @@ resp.is_streaming
 	Returns true when the response will be streamed
 	while being fetched from the backend.
 
+resp.filters
+
+	Type: STRING
+
+	Readable from: vcl_deliver, vcl_synth
+
+	Writable from: vcl_deliver, vcl_synth
+
+	List of VFP filters the resp.body will be pulled through.
 
 Special variables
 ~~~~~~~~~~~~~~~~~


More information about the varnish-commit mailing list