[master] d032984 Add bereq.body

Federico G. Schwindt fgsch at lodoss.net
Mon Jun 27 19:23:07 CEST 2016


commit d032984812ed4ec1362980dbf6c8f391bb94e68f
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Fri Jun 24 00:21:18 2016 +0100

    Add bereq.body
    
    Only available in vcl_backend_fetch{}. If it is unset varnish will not
    pass the request body to the backend.
    
    This is in preparation for addressing #1927.

diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 10879c0..a16e88b 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -409,6 +409,21 @@ VRT_r_beresp_backend(VRT_CTX)
 /*--------------------------------------------------------------------*/
 
 void
+VRT_l_bereq_body(VRT_CTX, const char *p, ...)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+	assert(p == vrt_magic_string_unset);
+	if (ctx->bo->req != NULL) {
+		CHECK_OBJ_NOTNULL(ctx->bo->req, REQ_MAGIC);
+		ctx->bo->req = NULL;
+		http_Unset(ctx->bo->bereq, H_Content_Length);
+	}
+}
+
+/*--------------------------------------------------------------------*/
+
+void
 VRT_l_req_esi(VRT_CTX, unsigned process_esi)
 {
 
diff --git a/bin/varnishtest/tests/v00018.vtc b/bin/varnishtest/tests/v00018.vtc
index 9c653ba..efeabda 100644
--- a/bin/varnishtest/tests/v00018.vtc
+++ b/bin/varnishtest/tests/v00018.vtc
@@ -67,11 +67,16 @@ varnish v1 -errvcl {Symbol not found: 'mu' (expected type BOOL):} {
 	sub vcl_backend_response { set beresp.do_gzip = mu; }
 }
 
-varnish v1 -errvcl {Only HTTP header variables can be unset.} {
+varnish v1 -errvcl {Only bereq.body and HTTP header variables can be unset.} {
 	backend b { .host = "127.0.0.1"; }
 	sub vcl_backend_response { unset beresp.do_gzip; }
 }
 
+varnish v1 -errvcl {bereq.body cannot be set.} {
+	backend b { .host = "127.0.0.1"; }
+	sub vcl_backend_fetch { set bereq.body = "foo"; }
+}
+
 varnish v1 -errvcl {Unknown token '<<' when looking for STRING} {
 	backend b { .host = "127.0.0.1"; }
 	sub vcl_recv { ban (<<); }
diff --git a/include/vrt.h b/include/vrt.h
index fa90786..9e8f13f 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -83,6 +83,7 @@ struct ws;
 typedef const struct vrt_acl *			VCL_ACL;
 typedef const struct director *			VCL_BACKEND;
 typedef const struct vmod_priv *		VCL_BLOB;
+typedef const char *				VCL_BODY;
 typedef unsigned				VCL_BOOL;
 typedef long long				VCL_BYTES;
 typedef double					VCL_DURATION;
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index ed7a2eb..4eaf69d 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -381,6 +381,13 @@ sp_variables = [
 		This is the backend or director we attempt to fetch from.
 		"""
 	),
+	('bereq.body',
+		'BODY',
+		(),
+		('backend_fetch',), """
+		The request body.
+		"""
+	),
 	('bereq.method',
 		'STRING',
 		('pipe', 'backend', ),
@@ -1164,7 +1171,7 @@ def one_var(nm, spec):
 		fo.write('\t    "VRT_l_%s(ctx, ",\n' % cnam)
 		if nm == i[0]:
 			fh.write("void VRT_l_%s(VRT_CTX, " % cnam)
-			if typ != "STRING":
+			if typ != "STRING" and typ != "BODY":
 				fh.write("VCL_" + typ + ");\n")
 			else:
 				fh.write(ctyp + ", ...);\n")
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index a2562f5..9494cbc 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -91,6 +91,11 @@ parse_set(struct vcc *tl)
 	sym = vcc_FindVar(tl, tl->t, 1, "cannot be set");
 	ERRCHK(tl);
 	assert(sym != NULL);
+	if (vcc_IdIs(tl->t, "bereq.body")) {
+		VSB_printf(tl->sb, "bereq.body cannot be set.\n");
+		vcc_ErrWhere(tl, tl->t);
+		return;
+	}
 	Fb(tl, 1, "%s\n", sym->lname);
 	tl->indent += INDENT;
 	vcc_NextToken(tl);
@@ -132,9 +137,10 @@ parse_unset(struct vcc *tl)
 	sym = vcc_FindVar(tl, tl->t, 1, "cannot be unset");
 	ERRCHK(tl);
 	assert(sym != NULL);
-	if (sym->fmt != HEADER) {
+	if (sym->fmt != HEADER && !vcc_IdIs(tl->t, "bereq.body")) {
 		VSB_printf(tl->sb,
-		    "Only HTTP header variables can be unset.\n");
+		    "Only bereq.body and HTTP header variables can"
+		    " be unset.\n");
 		vcc_ErrWhere(tl, tl->t);
 		return;
 	}
diff --git a/lib/libvcc/vcc_types.c b/lib/libvcc/vcc_types.c
index e98904c..a436baf 100644
--- a/lib/libvcc/vcc_types.c
+++ b/lib/libvcc/vcc_types.c
@@ -54,6 +54,11 @@ const struct type BLOB[1] = {{
 	.name =			"BLOB",
 }};
 
+const struct type BODY[1] = {{
+	.magic =		0xfae932d9,
+	.name =			"BODY",
+}};
+
 const struct type BOOL[1] = {{
 	.magic =		0xfae932d9,
 	.name =			"BOOL",
diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py
index 6275e13..6377adc 100755
--- a/lib/libvcc/vmodtool.py
+++ b/lib/libvcc/vmodtool.py
@@ -53,6 +53,7 @@ ctypes = {
 	'ACL':		"VCL_ACL",
 	'BACKEND':	"VCL_BACKEND",
 	'BLOB':		"VCL_BLOB",
+	'BODY':		"VCL_BODY",
 	'BOOL':		"VCL_BOOL",
 	'BYTES':	"VCL_BYTES",
 	'DURATION':	"VCL_DURATION",



More information about the varnish-commit mailing list