[master] 9b40808 Only bother/do g[un]zip if there actually is a beresp.body.

Poul-Henning Kamp phk at FreeBSD.org
Mon Jun 1 21:36:09 CEST 2015


commit 9b4080814677ae45cb858b97900046d96226c7d9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jun 1 19:35:03 2015 +0000

    Only bother/do g[un]zip if there actually is a beresp.body.
    
    Fixes:	#1746

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index b52354a..92a9c7f 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -563,19 +563,24 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	if (bo->htc->content_length == 0)
 		http_Unset(bo->beresp, H_Content_Encoding);
 
-	bo->is_gzip = http_HdrIs(bo->beresp, H_Content_Encoding, "gzip");
-
-	bo->is_gunzip = !http_GetHdr(bo->beresp, H_Content_Encoding, NULL);
-
-	/* It can't be both */
-	assert(bo->is_gzip == 0 || bo->is_gunzip == 0);
+	if (bo->htc->body_status != BS_NONE) {
+		bo->is_gzip =
+		    http_HdrIs(bo->beresp, H_Content_Encoding, "gzip");
+		bo->is_gunzip =
+		    !http_GetHdr(bo->beresp, H_Content_Encoding, NULL);
+		assert(bo->is_gzip == 0 || bo->is_gunzip == 0);
+	}
 
 	/* We won't gunzip unless it is non-empty and gzip'ed */
-	if (bo->htc->content_length == 0 || (bo->do_gunzip && !bo->is_gzip))
+	if (bo->htc->body_status == BS_NONE ||
+	    bo->htc->content_length == 0 ||
+	    (bo->do_gunzip && !bo->is_gzip))
 		bo->do_gunzip = 0;
 
 	/* We wont gzip unless it is non-empty and ungziped */
-	if (bo->htc->content_length == 0 || (bo->do_gzip && !bo->is_gunzip))
+	if (bo->htc->body_status == BS_NONE ||
+	    bo->htc->content_length == 0 ||
+	    (bo->do_gzip && !bo->is_gunzip))
 		bo->do_gzip = 0;
 
 	/* But we can't do both at the same time */
diff --git a/bin/varnishtest/tests/r01746.vtc b/bin/varnishtest/tests/r01746.vtc
new file mode 100644
index 0000000..0cc92f6
--- /dev/null
+++ b/bin/varnishtest/tests/r01746.vtc
@@ -0,0 +1,23 @@
+varnishtest "ESI include is 204"
+
+server s1 {
+	rxreq
+	txresp -gzipbody {<A><esi:include src="/b"/></A>}
+	rxreq
+	expect req.url == /b
+	txresp -status 204 -nolen \
+	    -hdr "Content-encoding: gzip" \
+	    -hdr "content-length: 10"
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_backend_response {
+		set beresp.do_esi = true;
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.body == "<A></A>"
+} -run



More information about the varnish-commit mailing list