[4.1] 368280d Ignore 0 Content-Lengths in 204 responses

Lasse Karstensen lkarsten at varnish-software.com
Thu Jan 14 15:15:08 CET 2016


commit 368280d4c30f28175d38dbdd9e587d0f80ed7631
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Fri Dec 4 16:08:06 2015 +0000

    Ignore 0 Content-Lengths in 204 responses
    
    Broken implementations do it contrary to what the RFC mandates.
    
    Fixes #1826.

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 17aba0e..fe26ac4 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -345,7 +345,8 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 		 * [RFC7230 3.3.1 p29 and 3.3.2 p31]
 		 */
 		wrk->stats->fetch_204++;
-		if (http_GetHdr(bo->beresp, H_Content_Length, NULL) ||
+		if ((http_GetHdr(bo->beresp, H_Content_Length, NULL) &&
+		    bo->htc->content_length != 0) ||
 		    http_GetHdr(bo->beresp, H_Transfer_Encoding, NULL))
 			bo->htc->body_status = BS_ERROR;
 		else
diff --git a/bin/varnishtest/tests/r01826.vtc b/bin/varnishtest/tests/r01826.vtc
new file mode 100644
index 0000000..eeb4503
--- /dev/null
+++ b/bin/varnishtest/tests/r01826.vtc
@@ -0,0 +1,15 @@
+varnishtest "Check we ignore a zero C-L with a 204"
+
+server s1 {
+	rxreq
+	txresp -status 204 -nolen -hdr "Content-Length: 0"
+} -start
+
+varnish v1 -vcl+backend {
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 204
+} -run



More information about the varnish-commit mailing list