[master] dc4e747 Call ESI_Deliver() as a VDP.

Poul-Henning Kamp phk at FreeBSD.org
Thu May 7 09:08:13 CEST 2015


commit dc4e7479de7d3a6f04e6cc1a80d097d748531e1d
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu May 7 06:30:14 2015 +0000

    Call ESI_Deliver() as a VDP.
    
    Only allow VDP_ungzip to set a length if it is the top VDP.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 2041a74..bad856f 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1107,7 +1107,6 @@ char *VRT_StringList(char *d, unsigned dl, const char *p, va_list ap);
 void VRTPRIV_init(struct vrt_privs *privs);
 void VRTPRIV_dynamic_kill(struct vrt_privs *privs, uintptr_t id);
 
-void ESI_Deliver(struct req *);
 void ESI_DeliverChild(struct req *, struct busyobj *);
 
 /* cache_vrt_vmod.c */
diff --git a/bin/varnishd/cache/cache_deliver_proc.c b/bin/varnishd/cache/cache_deliver_proc.c
index 86f4df2..34769c0 100644
--- a/bin/varnishd/cache/cache_deliver_proc.c
+++ b/bin/varnishd/cache/cache_deliver_proc.c
@@ -113,11 +113,6 @@ VDP_DeliverObj(struct req *req)
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 
-	if (req->res_mode & RES_ESI) {
-		ESI_Deliver(req);
-		return (OIS_DONE);
-	}
-
 	oi = ObjIterBegin(req->wrk, req->objcore);
 	XXXAN(oi);
 	AZ(req->synth_body);
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index bfa82ca..79d35d9 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -286,7 +286,7 @@ struct ecx {
 	int		isgzip;
 };
 
-static int __match_proto__(vdp_bytes)
+int __match_proto__(vdp_bytes)
 VDP_ESI(struct req *req, enum vdp_action act, void **priv,
     const void *ptr, ssize_t len)
 {
@@ -460,33 +460,6 @@ VDP_ESI(struct req *req, enum vdp_action act, void **priv,
 }
 
 /*---------------------------------------------------------------------
- */
-
-void
-ESI_Deliver(struct req *req)
-{
-	enum objiter_status ois;
-	void *sp = NULL;
-	ssize_t sl;
-	void *oi;
-	void *vp = NULL;
-
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
-
-	(void)VDP_ESI(req, VDP_INIT, &vp, NULL, 0);
-	oi = ObjIterBegin(req->wrk, req->objcore);
-	do {
-		ois = ObjIter(req->objcore, oi, &sp, &sl);
-		assert(ois != OIS_ERROR);
-		(void)VDP_ESI(req, VDP_FLUSH, &vp, sp, sl);
-	} while (ois != OIS_DONE);
-	(void)VDP_ESI(req, VDP_FINI, &vp, NULL, 0);
-	ObjIterEnd(req->objcore, &oi);
-}
-
-
-/*---------------------------------------------------------------------
  * Include an object in a gzip'ed ESI object delivery
  */
 
@@ -693,6 +666,8 @@ ESI_DeliverChild(struct req *req, struct busyobj *bo)
 		ved_stripgzip(req);
 		(void)VDP_bytes(req, VDP_FLUSH, NULL, 0);
 	} else {
+		if (req->res_mode & RES_ESI)
+			VDP_push(req, VDP_ESI, NULL, 0);
 		if (req->gzip_resp && !i)
 			VDP_push(req, ved_pretend_gzip, NULL, 0);
 		else if (!req->gzip_resp && i)
diff --git a/bin/varnishd/cache/cache_filter.h b/bin/varnishd/cache/cache_filter.h
index bbc3f8e..42f9c91 100644
--- a/bin/varnishd/cache/cache_filter.h
+++ b/bin/varnishd/cache/cache_filter.h
@@ -111,3 +111,4 @@ void VDP_close(struct req *req);
 enum objiter_status VDP_DeliverObj(struct req *req);
 
 vdp_bytes VDP_gunzip;
+vdp_bytes VDP_ESI;
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 041d890..3bc1ed0 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -296,8 +296,12 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
 		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)
+			/*
+			 * If the size is non-zero, and we are the top
+			 * VDP, we know what size the output will be.
+			 */
+			if (u != 0 &&
+			    VTAILQ_FIRST(&req->vdp)->func == VDP_gunzip)
 				req->resp_len = u;
 			else
 				req->resp_len = -1;
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index 27d4f72..c2cc57c 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -90,6 +90,7 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
 
 	if (req->res_mode & RES_ESI) {
 		RFC2616_Weaken_Etag(req->resp);
+		VDP_push(req, VDP_ESI, NULL, 0);
 	} else if (http_IsStatus(req->resp, 304)) {
 		http_Unset(req->resp, H_Content_Length);
 		req->wantbody = 0;
@@ -105,13 +106,13 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
 		 * XXX: with multiple writes because of the gunzip buffer
 		 */
 		req->res_mode |= RES_GUNZIP;
-		VDP_push(req, VDP_gunzip, NULL, 0);
+		VDP_push(req, VDP_gunzip, NULL, 1);
 	}
 
 	if (req->res_mode & RES_ESI) {
 		/* Gunzip could have added back a C-L */
 		http_Unset(req->resp, H_Content_Length);
-		req->resp_len = -1;
+		assert(req->resp_len < 0);
 	}
 
 	/*



More information about the varnish-commit mailing list