[master] dec75e0 Don't needlessly throw away Content-Length from backend, but assume it is sane and pass it to streaming clients, provided we don't munge the body along the way.

Poul-Henning Kamp phk at FreeBSD.org
Thu Oct 30 11:23:02 CET 2014


commit dec75e06706a0333d15473134ee368300fb42184
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Oct 30 10:21:27 2014 +0000

    Don't needlessly throw away Content-Length from backend, but assume
    it is sane and pass it to streaming clients, provided we don't munge
    the body along the way.
    
    Fixes: #1506

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index bfbd3c9..e83d06d 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -382,6 +382,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 			http_Unset(bo->beresp, H_Content_Encoding);
 			RFC2616_Weaken_Etag(bo->beresp);
 		}
+		http_Unset(bo->beresp, H_Content_Length);
 		HTTP_Merge(bo->wrk, bo->ims_oc, bo->beresp);
 		assert(http_IsStatus(bo->beresp, 200));
 		do_ims = 1;
diff --git a/bin/varnishtest/tests/r01506.vtc b/bin/varnishtest/tests/r01506.vtc
new file mode 100644
index 0000000..4f0ca76
--- /dev/null
+++ b/bin/varnishtest/tests/r01506.vtc
@@ -0,0 +1,42 @@
+varnishtest "Streaming of C-L header from backend"
+
+server s1 {
+	rxreq
+	txresp -nolen -hdr "Content-Length: 020"
+	send "0123456789"
+	sema r1 sync 2
+	send "0123456789"
+
+	rxreq
+	txresp -nolen -hdr "Content-Length: 010"
+	send "0123456789"
+} -start
+
+varnish v1 -vcl+backend {
+
+	sub vcl_backend_response {
+		if (bereq.url == "/2") {
+			set beresp.do_gzip = true;
+		}
+	}
+} -start -cliok "param.set debug +syncvsl"
+
+client c1 {
+	txreq
+	rxresphdrs
+	expect resp.http.content-length == "020"
+	sema r1 sync 2
+	rxrespbody
+	expect resp.body == "01234567890123456789"
+	delay .1
+
+	txreq -url "/2"
+	rxresp
+	expect resp.http.content-length == "<undef>"
+	expect resp.body == "0123456789"
+
+	delay .1
+	txreq -url "/2"
+	rxresp
+	expect resp.http.content-length == "10"
+} -run
diff --git a/include/tbl/http_headers.h b/include/tbl/http_headers.h
index 26443ca..0a5395f 100644
--- a/include/tbl/http_headers.h
+++ b/include/tbl/http_headers.h
@@ -57,7 +57,7 @@ HTTPH("Cache-Control",		H_Cache_Control,		       HTTPH_R_FETCH		  )	/* RFC2616 1
 HTTPH("Connection",		H_Connection,		HTTPH_R_PASS | HTTPH_R_FETCH | HTTPH_A_INS)	/* RFC2616 14.10 */
 HTTPH("Content-Encoding",	H_Content_Encoding,	0					  )	/* RFC2616 14.11 */
 HTTPH("Content-Language",	H_Content_Language,	0					  )	/* RFC2616 14.12 */
-HTTPH("Content-Length",		H_Content_Length,		       HTTPH_R_FETCH | HTTPH_A_INS)	/* RFC2616 14.13 */
+HTTPH("Content-Length",		H_Content_Length,		       HTTPH_R_FETCH		  )	/* RFC2616 14.13 */
 HTTPH("Content-Location",	H_Content_Location,	0					  )	/* RFC2616 14.14 */
 HTTPH("Content-MD5",		H_Content_MD5,		0					  )	/* RFC2616 14.15 */
 HTTPH("Content-Range",		H_Content_Range,		       HTTPH_R_FETCH | HTTPH_A_INS)	/* RFC2616 14.16 */



More information about the varnish-commit mailing list