r5688 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Wed Jan 5 14:07:50 CET 2011


Author: phk
Date: 2011-01-05 14:07:48 +0100 (Wed, 05 Jan 2011)
New Revision: 5688

Modified:
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_esi.c
   trunk/varnish-cache/bin/varnishd/cache_response.c
Log:
Further unravel og unify the response path.



Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2011-01-05 12:33:58 UTC (rev 5687)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2011-01-05 13:07:48 UTC (rev 5688)
@@ -190,6 +190,7 @@
 		sp->wrk->res_mode &= ~RES_LEN;
 		sp->wrk->res_mode |= RES_EOF;		/* XXX */
 		sp->wrk->res_mode |= RES_GUNZIP;
+		sp->doclose = "gunzip EOF";
 	}
 
 	if (!(sp->wrk->res_mode & (RES_LEN|RES_CHUNKED|RES_EOF))) {

Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi.c	2011-01-05 12:33:58 UTC (rev 5687)
+++ trunk/varnish-cache/bin/varnishd/cache_esi.c	2011-01-05 13:07:48 UTC (rev 5688)
@@ -867,7 +867,7 @@
 	CHECK_OBJ_NOTNULL(ed, ESIDATA_MAGIC);
 	VTAILQ_FOREACH(eb, &ed->esibits, list) {
 		if (Tlen(eb->verbatim)) {
-			if (sp->http->protover >= 1.1)
+			if (sp->wrk->res_mode & RES_CHUNKED)
 				(void)WRW_Write(w, eb->chunk_length, -1);
 			sp->acct_tmp.bodybytes += WRW_Write(w,
 			    eb->verbatim.b, Tlen(eb->verbatim));

Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2011-01-05 12:33:58 UTC (rev 5687)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2011-01-05 13:07:48 UTC (rev 5688)
@@ -178,11 +178,11 @@
 	http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
 	    "Content-Range: bytes %u-%u/%u", low, high, sp->obj->len);
 	http_Unset(sp->wrk->resp, H_Content_Length);
+	assert(sp->wrk->res_mode & RES_LEN);
 	http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
 	    "Content-Length: %u", 1 + high - low);
 	http_SetResp(sp->wrk->resp, "HTTP/1.1", 206, "Partial Content");
 
-
 	*plow = low;
 	*phigh = high;
 }
@@ -249,14 +249,33 @@
 	WRW_Reserve(sp->wrk, &sp->fd);
 
 	/*
+	 * If nothing special planned, we can attempt Range support
+	 */
+	low = 0;
+	high = sp->obj->len - 1;
+	if (!(sp->wrk->res_mode & (RES_ESI|RES_ESI_CHILD|RES_GUNZIP)) &&
+	    params->http_range_support && sp->obj->response == 200 &&
+	    sp->wantbody && http_GetHdr(sp->http, H_Range, &r))
+		res_dorange(sp, r, &low, &high);
+
+	if (sp->wrk->res_mode & RES_GUNZIP) {
+		assert(sp->wrk->res_mode & RES_EOF);
+		assert(!(sp->wrk->res_mode & (RES_ESI|RES_ESI_CHILD)));
+		AN(sp->doclose);
+		http_Unset(sp->wrk->resp, H_Content_Encoding);
+	}
+
+	/*
+	 * no headers for interior ESI includes 
+	 */
+	if (!(sp->wrk->res_mode & RES_ESI_CHILD))
+		sp->acct_tmp.hdrbytes +=
+		    http_Write(sp->wrk, sp->wrk->resp, 1);
+
+	/*
 	 * ESI objects get special delivery
 	 */
 	if (sp->wrk->res_mode & RES_ESI) {
-		if (!(sp->wrk->res_mode & RES_ESI_CHILD))
-			/* no headers for interior ESI includes */
-			sp->acct_tmp.hdrbytes +=
-			    http_Write(sp->wrk, sp->wrk->resp, 1);
-
 		if (WRW_FlushRelease(sp->wrk)) {
 			vca_close_session(sp, "remote closed");
 		} else if (sp->wantbody)
@@ -264,41 +283,32 @@
 		return;
 	}
 
+	if (!sp->wantbody) {
+		/* This was a HEAD request */
+		assert(sp->esis == 0);
+		if (WRW_FlushRelease(sp->wrk))
+			vca_close_session(sp, "remote closed");
+		return;
+	}
+
+	if (sp->obj->len == 0) {
+		if (WRW_FlushRelease(sp->wrk))
+			vca_close_session(sp, "remote closed");
+		return;
+	}
+
 	if (sp->wrk->res_mode & RES_GUNZIP) {
 		RES_WriteGunzipObj(sp);
 		return;
 	}
 
-	/*
-	 * How much of the object we want to deliver
-	 */
-	low = 0;
-	high = sp->obj->len - 1;
 
-	if (!(sp->wrk->res_mode & (RES_ESI|RES_ESI_CHILD))) {
-		/* For non-ESI and non ESI-included objects, try Range */
-		if (params->http_range_support &&
-		    (sp->disable_esi || sp->esis == 0) &&
-		    sp->obj->response == 200 &&
-		    sp->wantbody &&
-		    http_GetHdr(sp->http, H_Range, &r))
-			res_dorange(sp, r, &low, &high);
-
-		sp->acct_tmp.hdrbytes += http_Write(sp->wrk, sp->wrk->resp, 1);
-	} else if (sp->obj->len > 0 && (sp->wrk->res_mode & RES_CHUNKED)) {
+	if (sp->wrk->res_mode & RES_CHUNKED) {
 		assert(sp->wantbody);
 		sprintf(lenbuf, "%x\r\n", sp->obj->len);
 		(void)WRW_Write(sp->wrk, lenbuf, -1);
 	}
 
-	if (!sp->wantbody) {
-		/* This was a HEAD request */
-		assert(sp->esis == 0);
-		if (WRW_FlushRelease(sp->wrk))
-			vca_close_session(sp, "remote closed");
-		return;
-	}
-
 	ptr = 0;
 	VTAILQ_FOREACH(st, &sp->obj->store, list) {
 		CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
@@ -342,13 +352,9 @@
 		(void)WRW_Write(sp->wrk, st->ptr + off, len);
 	}
 	assert(u == sp->obj->len);
-	if (!sp->disable_esi &&
-	    sp->esis > 0 &&
-	    sp->http->protover >= 1.1 &&
-	    sp->obj->len > 0) {
+	if ((sp->wrk->res_mode & RES_CHUNKED))
 		/* post-chunk new line */
 		(void)WRW_Write(sp->wrk, "\r\n", -1);
-	}
 
 	if (WRW_FlushRelease(sp->wrk))
 		vca_close_session(sp, "remote closed");
@@ -364,9 +370,6 @@
 {
 	struct storage *st;
 	unsigned u = 0;
-#if 0
-	char lenbuf[20];
-#endif
 	struct vgz *vg;
 	const void *dp;
 	size_t dl;
@@ -375,51 +378,6 @@
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	AN(sp->wantbody);
 
-	/* We don't know the length  (XXX: Cache once we do ?) */
-	http_Unset(sp->wrk->resp, H_Content_Length);
-	http_Unset(sp->wrk->resp, H_Content_Encoding);
-	http_Unset(sp->wrk->resp, H_Connection);
-
-	http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Connection: %s",
-	    "close");
-	sp->doclose = "Gunzip EOF";
-
-	/*
-	 * ESI objects get special delivery
-	 */
-	if (!sp->disable_esi && sp->obj->esidata != NULL) {
-		INCOMPL();
-#if 0
-		if (sp->esis == 0)
-			/* no headers for interior ESI includes */
-			sp->acct_tmp.hdrbytes +=
-			    http_Write(sp->wrk, sp->wrk->resp, 1);
-
-		if (WRW_FlushRelease(sp->wrk)) {
-			vca_close_session(sp, "remote closed");
-		} else 
-			ESI_Deliver(sp);
-		return;
-#endif
-	}
-
-	if (sp->disable_esi || sp->esis == 0) {
-		sp->acct_tmp.hdrbytes += http_Write(sp->wrk, sp->wrk->resp, 1);
-	} else if (!sp->disable_esi &&
-	    sp->esis > 0 &&
-	    sp->http->protover >= 1.1 &&
-	    sp->obj->len > 0) {
-		INCOMPL();
-#if 0
-		/*
-		 * Interior ESI includes (which are not themselves ESI
-		 * objects) use chunked encoding (here) or EOF (nothing)
-		 */
-		sprintf(lenbuf, "%x\r\n", sp->obj->len);
-		(void)WRW_Write(sp->wrk, lenbuf, -1);
-#endif
-	}
-
 	vg = VGZ_NewUnzip(sp, sp->ws, sp->wrk->ws);
 	AN(vg);
 
@@ -443,16 +401,6 @@
 	}
 	VGZ_Destroy(&vg);
 	assert(u == sp->obj->len);
-	if (!sp->disable_esi &&
-	    sp->esis > 0 &&
-	    sp->http->protover >= 1.1 &&
-	    sp->obj->len > 0) {
-		INCOMPL();
-#if 0
-		/* post-chunk new line */
-		(void)WRW_Write(sp->wrk, "\r\n", -1);
-#endif
-	}
 
 	if (WRW_FlushRelease(sp->wrk))
 		vca_close_session(sp, "remote closed");




More information about the varnish-commit mailing list