[master] 7333dde Pull the protocol-agnostic bits of VDP (esi, range, gunzip) out of V1D and plunk it down in req_fsm for now.

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


commit 7333dde2148c6602f096bbeedffdf03212af0cbc
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu May 7 11:17:12 2015 +0000

    Pull the protocol-agnostic bits of VDP (esi, range, gunzip) out of V1D
    and plunk it down in req_fsm for now.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 71dc7b0..7c6a076 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -741,7 +741,7 @@ extern const int HTTP1_Req[3];
 extern const int HTTP1_Resp[3];
 
 /* cache_http1_deliver.c */
-void V1D_Deliver(struct req *, struct busyobj *);
+void V1D_Deliver(struct req *);
 
 /* cache_http1_pipe.c */
 void V1P_Init(void);
@@ -1107,7 +1107,7 @@ 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_DeliverChild(struct req *, struct busyobj *);
+int VED_Setup(struct req *req, struct busyobj *bo);
 
 /* cache_vrt_vmod.c */
 void VMOD_Init(void);
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index 79d35d9..7f072ea 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -653,11 +653,30 @@ ved_stripgzip(struct req *req)
 	req->l_crc += ilen;
 }
 
-void
-ESI_DeliverChild(struct req *req, struct busyobj *bo)
+int
+VED_Setup(struct req *req, struct busyobj *bo)
 {
 	int i;
 
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
+
+	/*
+	 * Determine ESI status first.  Not dependent on wantbody, because
+	 * we want ESI to supress C-L in HEAD too.
+	 */
+	if (!req->disable_esi &&
+	    ObjGetattr(req->wrk, req->objcore, OA_ESIDATA, NULL) != NULL) {
+		req->res_mode |= RES_ESI;
+		RFC2616_Weaken_Etag(req->resp);
+		req->resp_len = -1;
+		VDP_push(req, VDP_ESI, NULL, 0);
+	}
+
+	/* ESI-childen need special treatment */
+	if (req->esi_level == 0)
+		return (0);
+
 	req->res_mode |= RES_ESI_CHILD;
 	i = ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED);
 	if (req->gzip_resp && i && !(req->res_mode & RES_ESI)) {
@@ -666,8 +685,6 @@ 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)
@@ -676,4 +693,5 @@ ESI_DeliverChild(struct req *req, struct busyobj *bo)
 		(void)VDP_DeliverObj(req);
 	}
 	VDP_close(req);
+	return (1);
 }
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 42e67c3..590b5d7 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -40,12 +40,49 @@
 
 #include "cache.h"
 #include "cache_director.h"
+#include "cache_filter.h"
 
 #include "hash/hash_slinger.h"
 #include "vcl.h"
 #include "vsha256.h"
 #include "vtim.h"
 
+static void
+cnt_vdp(struct req *req, struct busyobj *bo)
+{
+	const char *r;
+
+	req->res_mode = 0;
+	if (bo != NULL)
+		req->resp_len = http_GetContentLength(bo->beresp);
+	else
+		req->resp_len = ObjGetLen(req->wrk, req->objcore);
+
+	if (VED_Setup(req, bo))
+		return;
+
+	if (cache_param->http_gzip_support &&
+	    ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED) &&
+	    !RFC2616_Req_Gzip(req->http)) {
+		req->res_mode |= RES_GUNZIP;
+		VDP_push(req, VDP_gunzip, NULL, 1);
+	}
+
+	/*
+	 * Range comes after the others and pushes on bottom because
+	 * it can generate a correct C-L header.
+	 */
+	if (cache_param->http_range_support &&
+	    http_IsStatus(req->resp, 200)) {
+		http_SetHeader(req->resp, "Accept-Ranges: bytes");
+		if (req->wantbody &&
+		    http_GetHdr(req->http, H_Range, &r))
+			VRG_dorange(req, r);
+	}
+
+	V1D_Deliver(req);
+}
+
 /*--------------------------------------------------------------------
  * Deliver an object to client
  */
@@ -144,7 +181,9 @@ cnt_deliver(struct worker *wrk, struct req *req)
 			VBO_DerefBusyObj(wrk, &bo);
 		}
 	}
-	V1D_Deliver(req, bo);
+
+	cnt_vdp(req, bo);
+
 	if (bo != NULL)
 		VBO_DerefBusyObj(wrk, &bo);
 
@@ -235,7 +274,7 @@ cnt_synth(struct worker *wrk, struct req *req)
 		VSB_delete(req->synth_body);
 		req->synth_body = NULL;
 
-		V1D_Deliver(req, NULL);
+		cnt_vdp(req, NULL);
 		(void)HSH_DerefObjCore(wrk, &req->objcore);
 	}
 
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index 19857c1..984a3f1 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -61,67 +61,13 @@ v1d_bytes(struct req *req, enum vdp_action act, void **priv,
  */
 
 void
-V1D_Deliver(struct req *req, struct busyobj *bo)
+V1D_Deliver(struct req *req)
 {
-	const char *r;
 	enum objiter_status ois;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
 
-	req->res_mode = 0;
-	if (bo != NULL)
-		req->resp_len = http_GetContentLength(bo->beresp);
-	else
-		req->resp_len = ObjGetLen(req->wrk, req->objcore);
-
-	/*
-	 * Determine ESI status first.  Not dependent on wantbody, because
-	 * we want ESI to supress C-L in HEAD too.
-	 */
-	if (!req->disable_esi &&
-	    ObjGetattr(req->wrk, req->objcore, OA_ESIDATA, NULL) != NULL)
-		req->res_mode |= RES_ESI;
-
-	/*
-	 * ESI-childen don't care about headers -> early escape
-	 */
-	if (req->esi_level > 0) {
-		ESI_DeliverChild(req, bo);
-		return;
-	}
-
-	if (req->res_mode & RES_ESI) {
-		RFC2616_Weaken_Etag(req->resp);
-		req->resp_len = -1;
-		VDP_push(req, VDP_ESI, NULL, 0);
-	}
-
-	if (cache_param->http_gzip_support &&
-	    ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED) &&
-	    !RFC2616_Req_Gzip(req->http)) {
-		/*
-		 * We don't know what it uncompresses to
-		 * XXX: we could cache that, but would still deliver
-		 * XXX: with multiple writes because of the gunzip buffer
-		 */
-		req->res_mode |= RES_GUNZIP;
-		VDP_push(req, VDP_gunzip, NULL, 1);
-	}
-
-	if (req->res_mode & RES_ESI)
-		assert(req->resp_len < 0);
-
-	/*
-	 * Range comes after the others and pushes on bottom because it
-	 * can generate a correct C-L header.
-	 */
-	if (cache_param->http_range_support && http_IsStatus(req->resp, 200)) {
-		http_SetHeader(req->resp, "Accept-Ranges: bytes");
-		if (req->wantbody && http_GetHdr(req->http, H_Range, &r))
-			VRG_dorange(req, r);
-	}
-
 	if ((req->objcore->flags & OC_F_PRIVATE) &&
 	    !strcasecmp(http_GetMethod(req->http0), "HEAD")) {
 		/* HEAD+pass is allowed to send the C-L through unmolested. */



More information about the varnish-commit mailing list