[master] ace59ccfe bereq: Also unset a cached req body

Nils Goroll nils.goroll at uplex.de
Mon May 22 13:05:14 UTC 2023


commit ace59ccfe8ad99aaa96dc5d9fdcda447086a1225
Author: Lachie <lachie at varnish-software.com>
Date:   Wed Apr 5 12:10:29 2023 +1000

    bereq: Also unset a cached req body

diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 2bd56b71a..1ec09a74c 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -35,6 +35,7 @@
 #include <stdio.h>
 
 #include "cache_varnishd.h"
+#include "cache_objhead.h"
 #include "cache_transport.h"
 #include "common/heritage.h"
 
@@ -612,6 +613,11 @@ VRT_u_bereq_body(VRT_CTX)
 {
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+	if (ctx->bo->bereq_body != NULL) {
+		HSH_DerefObjCore(ctx->bo->wrk, &ctx->bo->bereq_body, 0);
+		http_Unset(ctx->bo->bereq, H_Content_Length);
+	}
+
 	if (ctx->bo->req != NULL) {
 		CHECK_OBJ(ctx->bo->req, REQ_MAGIC);
 		ctx->bo->req = NULL;
diff --git a/bin/varnishtest/tests/v00068.vtc b/bin/varnishtest/tests/v00068.vtc
new file mode 100644
index 000000000..4b54a5ba0
--- /dev/null
+++ b/bin/varnishtest/tests/v00068.vtc
@@ -0,0 +1,33 @@
+varnishtest "unset bereq.body with cached req body"
+
+server s1 {
+	rxreq
+	expect req.method == "GET"
+	expect req.http.Content-Length == <undef>
+	txresp
+
+	rxreq
+	expect req.method == "GET"
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+	import std;
+
+	sub vcl_recv {
+		std.cache_req_body(2KB);
+	}
+	sub vcl_backend_fetch {
+		unset bereq.body;
+	}
+} -start
+
+client c1 {
+	txreq -body "fine"
+	rxresp
+	expect resp.status == 200
+
+	txreq
+	rxresp
+	expect resp.status == 200
+} -run


More information about the varnish-commit mailing list