[master] 0cf688b5d cache_fetch: Remove Content-Length when there is no bereq.body (any more)

Nils Goroll nils.goroll at uplex.de
Fri Feb 7 11:27:07 UTC 2025


commit 0cf688b5dd227dc4902ca3fd36a5fda14f90ea7f
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Fri Feb 7 12:17:37 2025 +0100

    cache_fetch: Remove Content-Length when there is no bereq.body (any more)
    
    Rather than specifically addressing rollbacks, simply remove Content-Length
    before calling VCL such that it can observe the missing Content-Length if there
    is no bereq.body.
    
    This way, the logic is consistent also for restarts from the client side.
    
    Fixes #4228

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 81608573a..dc842208b 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -408,11 +408,11 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 
 	http_PrintfHeader(bo->bereq, "X-Varnish: %ju", VXID(bo->vsl->wid));
 
-	VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo, NULL);
-
 	if (bo->bereq_body == NULL && bo->req == NULL)
 		http_Unset(bo->bereq, H_Content_Length);
 
+	VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo, NULL);
+
 	if (wrk->vpi->handling == VCL_RET_ABANDON ||
 	    wrk->vpi->handling == VCL_RET_FAIL)
 		return (F_STP_FAIL);
diff --git a/bin/varnishtest/tests/v00068.vtc b/bin/varnishtest/tests/v00068.vtc
index 2ccf30afe..cdab5e2dd 100644
--- a/bin/varnishtest/tests/v00068.vtc
+++ b/bin/varnishtest/tests/v00068.vtc
@@ -72,6 +72,11 @@ varnish v1 -vcl+backend {
 		if (bereq.http.restarts == "0") {
 			unset bereq.body;
 		}
+
+		if (bereq.http.Content-Length) {
+			return (abandon);
+		}
+
 		return (fetch);
 	}
 } -start


More information about the varnish-commit mailing list