Hi, The attached patch does:
1. Fix 0 Content-Lenth with gzip+esi. This is already handled in the non-esi case. 2. Make gzip handling with and without esi more inline. 3. Change some checks into asserts as they cannot really happen (the vfp won't get pushed). Thanks.
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c index 2963b95..e45c1e9 100644 --- a/bin/varnishd/cache/cache_esi_fetch.c +++ b/bin/varnishd/cache/cache_esi_fetch.c @@ -147,6 +147,14 @@ vfp_esi_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe) CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC); CHECK_OBJ_NOTNULL(vc->esi_req, HTTP_MAGIC); CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC); + + if (http_HdrIs(vc->http, H_Content_Length, "0")) { + http_Unset(vc->http, H_Content_Encoding); + return (VFP_NULL); + } + + assert(http_GetHdr(vc->http, H_Content_Encoding, NULL) == 0); + ALLOC_OBJ(vef, VEF_MAGIC); if (vef == NULL) return (VFP_ERROR); @@ -160,10 +168,9 @@ vfp_esi_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe) vef->ibuf_o = vef->ibuf; vfe->priv1 = vef; - RFC2616_Weaken_Etag(vc->http); - http_Unset(vc->http, H_Content_Length); - http_Unset(vc->http, H_Content_Encoding); http_SetHeader(vc->http, "Content-Encoding: gzip"); + http_Unset(vc->http, H_Content_Length); + RFC2616_Weaken_Etag(vc->http); RFC2616_Vary_AE(vc->http); diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c index 1e5b806..55be598 100644 --- a/bin/varnishd/cache/cache_gzip.c +++ b/bin/varnishd/cache/cache_gzip.c @@ -467,12 +467,10 @@ vfp_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe) } if (vfe->vfp->priv2 == VFP_GZIP) { - if (http_GetHdr(vc->http, H_Content_Encoding, NULL)) - return (VFP_NULL); + assert(http_GetHdr(vc->http, H_Content_Encoding, NULL) == 0); vg = VGZ_NewGzip(vc->vsl, vfe->vfp->priv1); } else { - if (!http_HdrIs(vc->http, H_Content_Encoding, "gzip")) - return (VFP_NULL); + assert(http_HdrIs(vc->http, H_Content_Encoding, "gzip") == 1); vg = VGZ_NewUngzip(vc->vsl, vfe->vfp->priv1); } if (vg == NULL) @@ -483,15 +481,16 @@ vfp_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe) VGZ_Ibuf(vg, vg->m_buf, 0); AZ(vg->m_len); - if (vfe->vfp->priv2 == VFP_GUNZIP || vfe->vfp->priv2 == VFP_GZIP) { + if (vfe->vfp->priv2 == VFP_GUNZIP) http_Unset(vc->http, H_Content_Encoding); + else if (vfe->vfp->priv2 == VFP_GZIP) + http_SetHeader(vc->http, "Content-Encoding: gzip"); + + if (vfe->vfp->priv2 == VFP_GUNZIP || vfe->vfp->priv2 == VFP_GZIP) { http_Unset(vc->http, H_Content_Length); RFC2616_Weaken_Etag(vc->http); } - if (vfe->vfp->priv2 == VFP_GZIP) - http_SetHeader(vc->http, "Content-Encoding: gzip"); - if (vfe->vfp->priv2 == VFP_GZIP || vfe->vfp->priv2 == VFP_TESTGUNZIP) RFC2616_Vary_AE(vc->http); diff --git a/bin/varnishtest/tests/e00029.vtc b/bin/varnishtest/tests/e00029.vtc new file mode 100644 index 0000000..7c780fc --- /dev/null +++ b/bin/varnishtest/tests/e00029.vtc @@ -0,0 +1,19 @@ +varnishtest "Test esi+gzip with zero C-L" + +server s1 { + rxreq + txresp -hdr "Content-Encoding: gzip" -hdr "Content-Length: 0" +} -start + +varnish v1 -vcl+backend { + sub vcl_backend_response { + set beresp.do_esi = true; + } +} -start + +client c1 { + txreq -hdr "Accept-Encoding: gzip" + rxresp + expect resp.http.Content-Encoding == <undef> + expect resp.bodylen == 0 +} -run
_______________________________________________ varnish-dev mailing list varnish-dev@varnish-cache.org https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev