[master] 18e7b5e Store the uncompressed size as part of OA_GZIP data and have VDP_gunzip() emit it as C-L if it looks sane.

Poul-Henning Kamp phk at FreeBSD.org
Wed Oct 29 11:56:13 CET 2014


commit 18e7b5e33c37fb1bc8d97a23aa01db02859bb676
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Oct 29 10:55:14 2014 +0000

    Store the uncompressed size as part of OA_GZIP data and have VDP_gunzip()
    emit it as C-L if it looks sane.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 1e0cec2..fb17acc 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -788,7 +788,7 @@ enum vgzret_e VGZ_Gzip(struct vgz *, const void **, ssize_t *len,
     enum vgz_flag);
 // enum vgzret_e VGZ_Gunzip(struct vgz *, const void **, ssize_t *len);
 enum vgzret_e VGZ_Destroy(struct vgz **);
-void VGZ_UpdateObj(const struct vfp_ctx *, const struct vgz*);
+void VGZ_UpdateObj(const struct vfp_ctx *, const struct vgz*, int input);
 
 /* cache_http.c */
 unsigned HTTP_estimate(unsigned nhttp);
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index 9091197..07d5503 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -130,7 +130,7 @@ vfp_esi_end(struct vfp_ctx *vc, struct vef_priv *vef,
 	}
 
 	if (vef->vgz != NULL) {
-		VGZ_UpdateObj(vc, vef->vgz);
+		VGZ_UpdateObj(vc, vef->vgz, 1);
 		if (VGZ_Destroy(&vef->vgz) != VGZ_END)
 			retval = VFP_Error(vc,
 			    "ESI+Gzip Failed at the very end");
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index f4e3796..1afd3cb 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -45,6 +45,7 @@
 #include "cache_filter.h"
 #include "vend.h"
 
+#include "vend.h"
 #include "vgz.h"
 
 struct vgz {
@@ -277,6 +278,8 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
 	const void *dp;
 	struct worker *wrk;
 	struct vgz *vg;
+	char *p;
+	uint64_t u;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	wrk = req->wrk;
@@ -289,7 +292,16 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
 			return (-1);
 		VGZ_Obuf(vg, vg->m_buf, vg->m_sz);
 		*priv = vg;
+
 		http_Unset(req->resp, H_Content_Length);
+		p = ObjGetattr(req->wrk, req->objcore, OA_GZIPBITS, &dl);
+		if (p != NULL && dl == 32) {
+			u = vbe64dec(p + 24);
+			/* XXX: Zero is suspect: OA_GZIPBITS wasn't set */
+			if (u != 0)
+				http_PrintfHeader(req->resp,
+				    "Content-Length: %ju", u);
+		}
 		http_Unset(req->resp, H_Content_Encoding);
 		return (0);
 	}
@@ -328,7 +340,7 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
 /*--------------------------------------------------------------------*/
 
 void
-VGZ_UpdateObj(const struct vfp_ctx *vc, const struct vgz *vg)
+VGZ_UpdateObj(const struct vfp_ctx *vc, const struct vgz *vg, int input)
 {
 	char *p;
 
@@ -338,6 +350,10 @@ VGZ_UpdateObj(const struct vfp_ctx *vc, const struct vgz *vg)
 	vbe64enc(p, vg->vz.start_bit);
 	vbe64enc(p + 8, vg->vz.last_bit);
 	vbe64enc(p + 16, vg->vz.stop_bit);
+	if (input)
+		vbe64enc(p + 24, vg->vz.total_in);
+	else
+		vbe64enc(p + 24, vg->vz.total_out);
 }
 
 /*--------------------------------------------------------------------
@@ -539,7 +555,7 @@ vfp_gzip_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
 
 	if (vr != VGZ_END)
 		return (VFP_Error(vc, "Gzip failed"));
-	VGZ_UpdateObj(vc, vg);
+	VGZ_UpdateObj(vc, vg, 1);
 	return (VFP_END);
 }
 
@@ -584,7 +600,7 @@ vfp_testgunzip_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
 	if (vp == VFP_END) {
 		if (vr != VGZ_END)
 			return (VFP_Error(vc, "tGunzip failed"));
-		VGZ_UpdateObj(vc, vg);
+		VGZ_UpdateObj(vc, vg, 0);
 	}
 	return (vp);
 }
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index c1f3b91..84cd582 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -89,7 +89,6 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
 
 	if (req->res_mode & RES_ESI) {
 		RFC2616_Weaken_Etag(req->resp);
-		http_Unset(req->resp, H_Content_Length);
 	} else if (http_IsStatus(req->resp, 304)) {
 		http_Unset(req->resp, H_Content_Length);
 		req->wantbody = 0;
@@ -112,6 +111,11 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
 		VDP_push(req, VDP_gunzip, NULL, 0);
 	}
 
+	if (req->res_mode & RES_ESI) {
+		/* Gunzip could have added back a C-L */
+		http_Unset(req->resp, H_Content_Length);
+	}
+
 	/*
 	 * Range comes after the others and pushes on bottom because it
 	 * can generate a correct C-L header.



More information about the varnish-commit mailing list