r4066 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl

sky at projects.linpro.no sky at projects.linpro.no
Sun May 10 23:21:37 CEST 2009


Author: sky
Date: 2009-05-10 23:21:36 +0200 (Sun, 10 May 2009)
New Revision: 4066

Added:
   trunk/varnish-cache/bin/varnishtest/tests/e00015.vtc
Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_esi.c
   trunk/varnish-cache/bin/varnishd/cache_response.c
   trunk/varnish-cache/bin/varnishd/cache_session.c
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
   trunk/varnish-cache/include/vrt_obj.h
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
   trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
   trunk/varnish-cache/lib/libvcl/vcc_obj.c
Log:
Allows you to turn off esi processing for a specific request using set req.esi = off even if the object has been esi processed -- this is useful if you have a cache heirarchy of varnish machines as well as debugging. Only change to processing is to store a copy of the attribute value instead of mangling to original. Committed from Oahu.

Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2009-05-09 16:49:49 UTC (rev 4065)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2009-05-10 21:21:36 UTC (rev 4066)
@@ -345,6 +345,7 @@
 
 	int			restarts;
 	int			esis;
+	int			disable_esi;
 
 	struct worker		*wrk;
 

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2009-05-09 16:49:49 UTC (rev 4065)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2009-05-10 21:21:36 UTC (rev 4066)
@@ -978,6 +978,8 @@
 	sp->director = sp->vcl->director[0];
 	AN(sp->director);
 
+      	sp->disable_esi = 0;
+	
 	VCL_recv_method(sp);
 	if (sp->restarts >= params->max_restarts) {
 		if (sp->err_code == 0)

Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi.c	2009-05-09 16:49:49 UTC (rev 4065)
+++ trunk/varnish-cache/bin/varnishd/cache_esi.c	2009-05-10 21:21:36 UTC (rev 4066)
@@ -304,8 +304,7 @@
 	in->b++;
 
 	if (isspace(*in->b)) {
-		val->e = val->b = in->b;;
-		*val->e = '\0';
+		val->e = val->b = in->b;
 		in->b++;
 		return (1);
 	}
@@ -340,7 +339,6 @@
 		val->e = in->b;
 		in->b++;
 	}
-	*val->e = '\0';
 	return (1);
 }
 
@@ -352,11 +350,11 @@
 esi_handle_include(struct esi_work *ew)
 {
 	struct esi_bit *eb;
-	char *p, *q;
+	char *p, *q, *c;
 	txt t = ew->tag;
 	txt tag;
 	txt val;
-	unsigned u, v;
+	unsigned u, v, s;
 	struct ws *ws;
 
 	if (ew->eb == NULL || ew->eb->include.b != NULL)
@@ -375,6 +373,20 @@
 			continue;
 		}
 
+		/* Wee are saving the original string */
+		ws = ew->sp->obj->ws_o;
+		WS_Assert(ws);
+		s = 0;
+
+		if ( val.b != val.e ) {
+			s = Tlen(val) + 1;
+			c = WS_Alloc(ws, s);
+			memcpy(c, val.b, Tlen(val));
+			val.b = c;
+			val.e = val.b + s;
+			*val.e = '\0';
+		}
+
 		if (Tlen(val) > 7 && !memcmp(val.b, "http://", 7)) {
 			/*  Rewrite to Host: header inplace */
 			eb->host.b = val.b;
@@ -405,8 +417,6 @@
 
 			/* Use the objects WS to store the result */
 			CHECK_OBJ_NOTNULL(ew->sp->obj, OBJECT_MAGIC);
-			ws = ew->sp->obj->ws_o;
-			WS_Assert(ws);
 
 			/* Look for the last '/' before a '?' */
 			q = NULL;

Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2009-05-09 16:49:49 UTC (rev 4065)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2009-05-10 21:21:36 UTC (rev 4066)
@@ -106,7 +106,7 @@
 	    HTTPH_A_DELIVER);
 
 	/* Only HTTP 1.1 can do Chunked encoding */
-	if (!VTAILQ_EMPTY(&sp->obj->esibits)) {
+	if (!sp->disable_esi && !VTAILQ_EMPTY(&sp->obj->esibits)) {
 		http_Unset(sp->wrk->resp, H_Content_Length);
 		if(sp->http->protover >= 1.1)
 			http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Transfer-Encoding: chunked");
@@ -142,10 +142,10 @@
 
 	WRW_Reserve(sp->wrk, &sp->fd);
 
-	if (sp->esis == 0)
+	if (!sp->disable_esi == 0 || sp->esis == 0)
 		sp->acct_req.hdrbytes += http_Write(sp->wrk, sp->wrk->resp, 1);
 
-	if (sp->wantbody && !VTAILQ_EMPTY(&sp->obj->esibits)) {
+	if (!sp->disable_esi && sp->wantbody && !VTAILQ_EMPTY(&sp->obj->esibits)) {
 		if (WRW_FlushRelease(sp->wrk)) {
 			vca_close_session(sp, "remote closed");
 			return;
@@ -155,7 +155,8 @@
 	}
 
 	if (sp->wantbody) {
-		if (sp->esis > 0 &&
+		if (!sp->disable_esi &&
+		    sp->esis > 0 &&
 		    sp->http->protover >= 1.1 &&
 		    sp->obj->len > 0) {
 			sprintf(lenbuf, "%x\r\n", sp->obj->len);
@@ -186,7 +187,8 @@
 			(void)WRW_Write(sp->wrk, st->ptr, st->len);
 		}
 		assert(u == sp->obj->len);
-		if (sp->esis > 0 &&
+		if (!sp->disable_esi &&
+		    sp->esis > 0 &&
 		    sp->http->protover >= 1.1 &&
 		    sp->obj->len > 0)
 			(void)WRW_Write(sp->wrk, "\r\n", -1);

Modified: trunk/varnish-cache/bin/varnishd/cache_session.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_session.c	2009-05-09 16:49:49 UTC (rev 4065)
+++ trunk/varnish-cache/bin/varnishd/cache_session.c	2009-05-10 21:21:36 UTC (rev 4066)
@@ -161,7 +161,8 @@
 	sp->t_resp = NAN;
 	sp->t_end = NAN;
 	sp->grace = NAN;
-
+	sp->disable_esi = 0;
+	
 	assert(len <= sp->sockaddrlen);
 	if (addr != NULL) {
 		memcpy(sp->sockaddr, addr, len);

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2009-05-09 16:49:49 UTC (rev 4065)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2009-05-10 21:21:36 UTC (rev 4066)
@@ -554,6 +554,22 @@
 
 /*--------------------------------------------------------------------*/
 
+void
+VRT_l_req_esi(struct sess *sp, unsigned process_esi)
+{
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	sp->disable_esi = !process_esi;
+}
+
+unsigned
+VRT_r_req_esi(struct sess *sp)
+{
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	return (!sp->disable_esi);
+}
+
+/*--------------------------------------------------------------------*/
+
 int
 VRT_r_req_restarts(const struct sess *sp)
 {

Added: trunk/varnish-cache/bin/varnishtest/tests/e00015.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/e00015.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/e00015.vtc	2009-05-10 21:21:36 UTC (rev 4066)
@@ -0,0 +1,49 @@
+# $Id: e00003.vtc 3573 2009-02-03 18:44:21Z phk $
+
+test "ESI requests turned off"
+
+
+server s1 {
+	rxreq 
+	txresp -body {
+		<html>
+		Before include
+		<esi:include src="/body"/>
+		After include
+	}
+	rxreq 
+	txresp -body {
+		<html>
+		Before include
+		<esi:include src="/body"/>
+		After include
+	}
+	rxreq 
+	expect req.url == "/body"
+	txresp -body {
+		Included file
+	}
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_fetch {
+	    	if(req.url == "/") {
+ 	    	   set req.esi = false;
+		}
+		esi;
+	}
+} -start
+
+client c1 {
+        txreq
+	rxresp
+	expect resp.bodylen == 73
+	expect resp.status == 200
+	txreq -url "/esi"
+	rxresp
+	expect resp.bodylen == 65
+	expect resp.status == 200
+}
+
+client c1 -run
+varnish v1 -expect esi_errors == 0

Modified: trunk/varnish-cache/include/vrt_obj.h
===================================================================
--- trunk/varnish-cache/include/vrt_obj.h	2009-05-09 16:49:49 UTC (rev 4065)
+++ trunk/varnish-cache/include/vrt_obj.h	2009-05-10 21:21:36 UTC (rev 4066)
@@ -24,6 +24,8 @@
 double VRT_r_req_grace(struct sess *);
 void VRT_l_req_grace(struct sess *, double);
 const char * VRT_r_req_xid(struct sess *);
+unsigned VRT_r_req_esi(struct sess *);
+void VRT_l_req_esi(struct sess *, unsigned);
 const char * VRT_r_bereq_request(const struct sess *);
 void VRT_l_bereq_request(const struct sess *, const char *, ...);
 const char * VRT_r_bereq_url(const struct sess *);

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2009-05-09 16:49:49 UTC (rev 4065)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2009-05-10 21:21:36 UTC (rev 4066)
@@ -233,8 +233,8 @@
 	vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI");
 	vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT");
 	vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n");
-	vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3834 2009-02-27 12:");
-	vsb_cat(sb, "02:50Z phk $\n *\n * Runtime support for compiled VCL ");
+	vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 4025 2009-04-03 21:");
+	vsb_cat(sb, "52:44Z des $\n *\n * Runtime support for compiled VCL ");
 	vsb_cat(sb, "programs.\n *\n * XXX: When this file is changed, lib/");
 	vsb_cat(sb, "libvcl/vcc_gen_fixed_token.tcl\n");
 	vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n");
@@ -343,6 +343,8 @@
 	vsb_cat(sb, "uct sess *);\ndouble VRT_r_req_grace(struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_req_grace(struct sess *, double);\n");
 	vsb_cat(sb, "const char * VRT_r_req_xid(struct sess *);\n");
+	vsb_cat(sb, "unsigned VRT_r_req_esi(struct sess *);\n");
+	vsb_cat(sb, "void VRT_l_req_esi(struct sess *, unsigned);\n");
 	vsb_cat(sb, "const char * VRT_r_bereq_request(const struct sess *);");
 	vsb_cat(sb, "\nvoid VRT_l_bereq_request(const struct sess *, const ");
 	vsb_cat(sb, "char *, ...);\nconst char * VRT_r_bereq_url(const stru");

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2009-05-09 16:49:49 UTC (rev 4065)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2009-05-10 21:21:36 UTC (rev 4066)
@@ -116,6 +116,12 @@
 	"struct sess *"
     }
 
+    { req.esi
+	RW BOOL
+	{recv fetch deliver					   error}
+	"struct sess *"
+    }
+
     #######################################################################
     # Request sent to backend
     { bereq.request

Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_obj.c	2009-05-09 16:49:49 UTC (rev 4065)
+++ trunk/varnish-cache/lib/libvcl/vcc_obj.c	2009-05-10 21:21:36 UTC (rev 4066)
@@ -107,6 +107,11 @@
 	     | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
 	     | VCL_MET_ERROR
 	},
+	{ "req.esi", BOOL, 7,
+	    "VRT_r_req_esi(sp)",	    "VRT_l_req_esi(sp, ",
+	    V_RW,	    0,
+	    VCL_MET_RECV | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_ERROR
+	},
 	{ "bereq.request", STRING, 13,
 	    "VRT_r_bereq_request(sp)",	    "VRT_l_bereq_request(sp, ",
 	    V_RW,	    0,



More information about the varnish-commit mailing list