[master] e0e89a6 Move the header-munging to the VFP's that require it.

Poul-Henning Kamp phk at FreeBSD.org
Wed Jul 9 20:53:30 CEST 2014


commit e0e89a69d93ed004174318f37a5bda960a9d3ebd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jul 9 18:52:58 2014 +0000

    Move the header-munging to the VFP's that require it.

diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index ba8c065..3601cf8 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -157,10 +157,15 @@ vfp_esi_gzip_init(struct busyobj *bo, struct vfp_entry *vfe)
 	vef->ibuf = calloc(1L, vef->ibuf_sz);
 	if (vef->ibuf == NULL)
 		return (vfp_esi_end(bo, vef, VFP_ERROR));
-	XXXAN(vef->ibuf);
 	vef->ibuf_i = vef->ibuf;
 	vef->ibuf_o = vef->ibuf;
 	vfe->priv1 = vef;
+
+	RFC2616_Weaken_Etag(bo->beresp);
+	http_Unset(bo->beresp, H_Content_Length);
+	http_Unset(bo->beresp, H_Content_Encoding);
+	http_SetHeader(bo->beresp, "Content-Encoding: gzip");
+
 	return (VFP_OK);
 }
 
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index b31e2e2..cf1da26 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -446,28 +446,17 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	/* But we can't do both at the same time */
 	assert(bo->do_gzip == 0 || bo->do_gunzip == 0);
 
-	/* Fix Content-Encoding, as appropriate */
-	if (bo->do_gzip)
-		http_SetHeader(bo->beresp, "Content-Encoding: gzip");
-	else if (bo->do_gunzip)
-		http_Unset(bo->beresp, H_Content_Encoding);
-
-	if (bo->do_gunzip || (bo->is_gzip && bo->do_esi)) {
-		RFC2616_Weaken_Etag(bo->beresp);
+	if (bo->do_gunzip || (bo->is_gzip && bo->do_esi))
 		VFP_Push(bo, &vfp_gunzip, 0, 1);
-	}
 
 	if (bo->do_esi && bo->do_gzip) {
 		VFP_Push(bo, &vfp_esi_gzip, 0, 1);
-		RFC2616_Weaken_Etag(bo->beresp);
 	} else if (bo->do_esi && bo->is_gzip && !bo->do_gunzip) {
 		VFP_Push(bo, &vfp_esi_gzip, 0, 1);
-		RFC2616_Weaken_Etag(bo->beresp);
 	} else if (bo->do_esi) {
 		VFP_Push(bo, &vfp_esi, 0, 1);
 	} else if (bo->do_gzip) {
 		VFP_Push(bo, &vfp_gzip, 0, 1);
-		RFC2616_Weaken_Etag(bo->beresp);
 	} else if (bo->is_gzip && !bo->do_gunzip) {
 		VFP_Push(bo, &vfp_testgunzip, 0, 1);
 	}
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index c0f2859..e684089 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -458,13 +458,20 @@ vfp_gzip_init(struct busyobj *bo, struct vfp_entry *vfe)
         CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
 
-	if (bo->content_length == 0)
+	if (bo->content_length == 0) {
+		http_Unset(bo->beresp, H_Content_Encoding);
 		return (VFP_NULL);
+	}
 
-	if (vfe->vfp->priv2 == VFP_GZIP)
+	if (vfe->vfp->priv2 == VFP_GZIP) {
+		if (http_GetHdr(bo->beresp, H_Content_Encoding, NULL))
+			return (VFP_NULL);
 		vg = VGZ_NewGzip(bo->vsl, vfe->vfp->priv1);
-	else
+	} else {
+		if (!http_HdrIs(bo->beresp, H_Content_Encoding, "gzip"))
+			return (VFP_NULL);
 		vg = VGZ_NewUngzip(bo->vsl, vfe->vfp->priv1);
+	}
 	if (vg == NULL)
 		return (VFP_ERROR);
 	vfe->priv1 = vg;
@@ -472,6 +479,16 @@ vfp_gzip_init(struct busyobj *bo, struct vfp_entry *vfe)
 		return (VFP_ERROR);
 	VGZ_Ibuf(vg, vg->m_buf, 0);
 	AZ(vg->m_len);
+
+	if (vfe->vfp->priv2 == VFP_GUNZIP || vfe->vfp->priv2 == VFP_GZIP) {
+		http_Unset(bo->beresp, H_Content_Encoding);
+		http_Unset(bo->beresp, H_Content_Length);
+		RFC2616_Weaken_Etag(bo->beresp);
+	}
+
+	if (vfe->vfp->priv2 == VFP_GZIP)
+		http_SetHeader(bo->beresp, "Content-Encoding: gzip");
+
 	return (VFP_OK);
 }
 



More information about the varnish-commit mailing list