[master] 3f533abb9 Collect everything related to beresp.filter_list in one source file

Poul-Henning Kamp phk at FreeBSD.org
Thu Oct 11 09:10:16 UTC 2018


commit 3f533abb9ba1d0200d70b4d4e10b29ccdf9d2244
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Oct 11 09:09:03 2018 +0000

    Collect everything related to beresp.filter_list in one source file

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 1235313e0..9a08a37c6 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -498,97 +498,6 @@ vbf_stp_fetchbody(struct worker *wrk, struct busyobj *bo)
 	ObjTrimStore(wrk, vfc->oc);
 	return (F_STP_FETCHEND);
 }
-
-/*--------------------------------------------------------------------
- */
-
-static void
-vbf_default_filter_list(const struct busyobj *bo, struct vsb *vsb)
-{
-	const char *p;
-	int do_gzip = bo->do_gzip;
-	int do_gunzip = bo->do_gunzip;
-	int is_gzip = 0, is_gunzip = 0;
-
-	/*
-	 * The VCL variables beresp.do_g[un]zip tells us how we want the
-	 * object processed before it is stored.
-	 *
-	 * The backend Content-Encoding header tells us what we are going
-	 * to receive, which we classify in the following three classes:
-	 *
-	 *	"Content-Encoding: gzip"	--> object is gzip'ed.
-	 *	no Content-Encoding		--> object is not gzip'ed.
-	 *	anything else			--> do nothing wrt gzip
-	 */
-
-	/* No body -> done */
-	if (bo->htc->body_status == BS_NONE || bo->htc->content_length == 0)
-		return;
-
-	if (!cache_param->http_gzip_support)
-		do_gzip = do_gunzip = 0;
-
-	if (http_GetHdr(bo->beresp, H_Content_Encoding, &p))
-		is_gzip = !strcasecmp(p, "gzip");
-	else
-		is_gunzip = 1;
-
-	/* We won't gunzip unless it is gzip'ed */
-	if (do_gunzip && !is_gzip)
-		do_gunzip = 0;
-
-	/* We wont gzip unless if it already is gzip'ed */
-	if (do_gzip && !is_gunzip)
-		do_gzip = 0;
-
-	if (do_gunzip || (is_gzip && bo->do_esi))
-		VSB_cat(vsb, " gunzip");
-
-	if (bo->do_esi && (do_gzip || (is_gzip && !do_gunzip))) {
-		VSB_cat(vsb, " esi_gzip");
-		return;
-	}
-
-	if (bo->do_esi) {
-		VSB_cat(vsb, " esi");
-		return;
-	}
-
-	if (do_gzip)
-		VSB_cat(vsb, " gzip");
-
-	if (is_gzip && !do_gunzip)
-		VSB_cat(vsb, " testgunzip");
-}
-
-const char *
-VBF_Get_Filter_List(struct busyobj *bo)
-{
-	unsigned u;
-	struct vsb vsb[1];
-
-	u = WS_Reserve(bo->ws, 0);
-	if (u == 0) {
-		WS_Release(bo->ws, 0);
-		WS_MarkOverflow(bo->ws);
-		return (NULL);
-	}
-	AN(VSB_new(vsb, bo->ws->f, u, VSB_FIXEDLEN));
-	vbf_default_filter_list(bo, vsb);
-	if (VSB_finish(vsb)) {
-		WS_Release(bo->ws, 0);
-		WS_MarkOverflow(bo->ws);
-		return (NULL);
-	}
-	if (VSB_len(vsb)) {
-		WS_Release(bo->ws, VSB_len(vsb) + 1);
-		return (VSB_data(vsb) + 1);
-	}
-	WS_Release(bo->ws, 0);
-	return ("");
-}
-
 static enum fetch_step
 vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 {
diff --git a/bin/varnishd/cache/cache_vrt_filter.c b/bin/varnishd/cache/cache_vrt_filter.c
index 653029da1..9ad6a7620 100644
--- a/bin/varnishd/cache/cache_vrt_filter.c
+++ b/bin/varnishd/cache/cache_vrt_filter.c
@@ -36,8 +36,10 @@
 #include <stdlib.h>
 
 #include "vct.h"
+
 #include "cache_varnishd.h"
 #include "cache_vcl.h"
+#include "vrt_obj.h"
 
 #include "cache_filter.h"
 
@@ -142,3 +144,125 @@ VCL_VRT_Init(void)
 	VRT_AddVFP(NULL, &VFP_esi);
 	VRT_AddVFP(NULL, &VFP_esi_gzip);
 }
+
+/*--------------------------------------------------------------------
+ */
+
+static void
+vbf_default_filter_list(const struct busyobj *bo, struct vsb *vsb)
+{
+	const char *p;
+	int do_gzip = bo->do_gzip;
+	int do_gunzip = bo->do_gunzip;
+	int is_gzip = 0, is_gunzip = 0;
+
+	/*
+	 * The VCL variables beresp.do_g[un]zip tells us how we want the
+	 * object processed before it is stored.
+	 *
+	 * The backend Content-Encoding header tells us what we are going
+	 * to receive, which we classify in the following three classes:
+	 *
+	 *	"Content-Encoding: gzip"	--> object is gzip'ed.
+	 *	no Content-Encoding		--> object is not gzip'ed.
+	 *	anything else			--> do nothing wrt gzip
+	 */
+
+	/* No body -> done */
+	if (bo->htc->body_status == BS_NONE || bo->htc->content_length == 0)
+		return;
+
+	if (!cache_param->http_gzip_support)
+		do_gzip = do_gunzip = 0;
+
+	if (http_GetHdr(bo->beresp, H_Content_Encoding, &p))
+		is_gzip = !strcasecmp(p, "gzip");
+	else
+		is_gunzip = 1;
+
+	/* We won't gunzip unless it is gzip'ed */
+	if (do_gunzip && !is_gzip)
+		do_gunzip = 0;
+
+	/* We wont gzip unless if it already is gzip'ed */
+	if (do_gzip && !is_gunzip)
+		do_gzip = 0;
+
+	if (do_gunzip || (is_gzip && bo->do_esi))
+		VSB_cat(vsb, " gunzip");
+
+	if (bo->do_esi && (do_gzip || (is_gzip && !do_gunzip))) {
+		VSB_cat(vsb, " esi_gzip");
+		return;
+	}
+
+	if (bo->do_esi) {
+		VSB_cat(vsb, " esi");
+		return;
+	}
+
+	if (do_gzip)
+		VSB_cat(vsb, " gzip");
+
+	if (is_gzip && !do_gunzip)
+		VSB_cat(vsb, " testgunzip");
+}
+
+const char *
+VBF_Get_Filter_List(struct busyobj *bo)
+{
+	unsigned u;
+	struct vsb vsb[1];
+
+	u = WS_Reserve(bo->ws, 0);
+	if (u == 0) {
+		WS_Release(bo->ws, 0);
+		WS_MarkOverflow(bo->ws);
+		return (NULL);
+	}
+	AN(VSB_new(vsb, bo->ws->f, u, VSB_FIXEDLEN));
+	vbf_default_filter_list(bo, vsb);
+	if (VSB_finish(vsb)) {
+		WS_Release(bo->ws, 0);
+		WS_MarkOverflow(bo->ws);
+		return (NULL);
+	}
+	if (VSB_len(vsb)) {
+		WS_Release(bo->ws, VSB_len(vsb) + 1);
+		return (VSB_data(vsb) + 1);
+	}
+	WS_Release(bo->ws, 0);
+	return ("");
+}
+
+/*--------------------------------------------------------------------*/
+
+VCL_STRING
+VRT_r_beresp_filters(VRT_CTX)
+{
+
+	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));
+}
+
+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;
+	}
+	ctx->bo->filter_list = b;
+}
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 7cb3feb17..e9e821f11 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -922,35 +922,3 @@ HTTP_VAR(req)
 HTTP_VAR(resp)
 HTTP_VAR(bereq)
 HTTP_VAR(beresp)
-
-/*--------------------------------------------------------------------*/
-
-VCL_STRING
-VRT_r_beresp_filters(VRT_CTX)
-{
-
-	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));
-}
-
-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;
-	}
-	ctx->bo->filter_list = b;
-}


More information about the varnish-commit mailing list