[4.0] ac21ca0 If the backend sends "Content-Length: 0" and "Content_Encoding: gzip" it is buggy, work around it. If the backend sends chunked encoding we don't catch it and fail the transfer.

Poul-Henning Kamp phk at FreeBSD.org
Tue Apr 1 15:09:53 CEST 2014


commit ac21ca073d7a93268e9f7340519e2e9cc8db1d00
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Mar 25 10:46:35 2014 +0000

    If the backend sends "Content-Length: 0" and "Content_Encoding: gzip"
    it is buggy, work around it.  If the backend sends chunked encoding
    we don't catch it and fail the transfer.
    
    Fixes: #1320

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 93be439..ecbcf2e 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -416,6 +416,20 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	if (bo->do_gzip && !bo->is_gunzip)
 		bo->do_gzip = 0;
 
+	AN(bo->vbc);
+	est = V1F_Setup_Fetch(bo);
+
+	if (est == 0) {
+		/*
+		 * If the length is known to be zero, it's not gziped.
+		 * A similar issue exists for chunked encoding but we
+		 * don't handle that.  See #1320.
+		 */
+		http_Unset(bo->beresp, H_Content_Encoding);
+		bo->is_gzip = 0;
+		bo->is_gunzip = 1;
+	}
+
 	/* But we can't do both at the same time */
 	assert(bo->do_gzip == 0 || bo->do_gunzip == 0);
 
@@ -425,9 +439,6 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	else if (bo->do_gunzip)
 		http_Unset(bo->beresp, H_Content_Encoding);
 
-	AN(bo->vbc);
-	est = V1F_Setup_Fetch(bo);
-
 	if (bo->do_gunzip || (bo->is_gzip && bo->do_esi)) {
 		RFC2616_Weaken_Etag(bo->beresp);
 		VFP_Push(bo, vfp_gunzip_pull, 0);
diff --git a/bin/varnishtest/tests/r01320.vtc b/bin/varnishtest/tests/r01320.vtc
new file mode 100644
index 0000000..568699d
--- /dev/null
+++ b/bin/varnishtest/tests/r01320.vtc
@@ -0,0 +1,15 @@
+varnishtest "#1320 zero-length gzip"
+
+server s1 {
+	rxreq
+	txresp -hdr "Content-Encoding: gzip"
+} -start
+
+varnish v1 -vcl+backend { } -start
+
+
+client c1 {
+	txreq -hdr "Accept-Encoding: gzip"
+	rxresp
+	expect resp.status == 200
+} -run



More information about the varnish-commit mailing list