[3.0] 7298173 Only emit passed Content_Length header when response mode is RES_LEN

Martin Blix Grydeland martin at varnish-software.com
Mon Mar 16 16:10:51 CET 2015


commit 72981734a141a0a52172b85bae55f8877f69ff42
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Mon Mar 16 11:49:11 2015 +0100

    Only emit passed Content_Length header when response mode is RES_LEN
    
    Original patch and test case by: tnt
    
    Fixes: #1627

diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c
index 160dda7..e976297 100644
--- a/bin/varnishd/cache_response.c
+++ b/bin/varnishd/cache_response.c
@@ -351,9 +351,9 @@ RES_StreamStart(struct sess *sp)
 	if (sp->wrk->res_mode & RES_GUNZIP)
 		http_Unset(sp->wrk->resp, H_Content_Encoding);
 
-	if (!(sp->wrk->res_mode & RES_CHUNKED) &&
-	    sp->wrk->h_content_length != NULL) {
-		http_Unset(sp->wrk->resp, H_Content_Length);
+	http_Unset(sp->wrk->resp, H_Content_Length);
+	if (sp->wrk->res_mode & RES_LEN) {
+		AN(sp->wrk->h_content_length);
 		http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
 		    "Content-Length: %s", sp->wrk->h_content_length);
 	}
diff --git a/bin/varnishtest/tests/r01627.vtc b/bin/varnishtest/tests/r01627.vtc
new file mode 100644
index 0000000..1cbc9dd
--- /dev/null
+++ b/bin/varnishtest/tests/r01627.vtc
@@ -0,0 +1,21 @@
+varnishtest "Regression test for #1627: Wrong Content-Length for gzipped+streamed content with HTTP/1.0 client"
+
+server s1 {
+	rxreq
+	txresp -body {Testing}
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_fetch {
+		set beresp.do_stream = true;
+		set beresp.do_gzip = true;
+	}
+} -start
+
+client c1 {
+	txreq -proto "HTTP/1.0" -hdr "Accept-Encoding: gzip"
+	rxresp
+	expect resp.http.content-length == "<undef>"
+	gunzip
+	expect resp.bodylen == 7
+} -run



More information about the varnish-commit mailing list