r5730 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Thu Jan 13 12:55:11 CET 2011


Author: phk
Date: 2011-01-13 12:55:11 +0100 (Thu, 13 Jan 2011)
New Revision: 5730

Modified:
   trunk/varnish-cache/bin/varnishd/cache_esi_deliver.c
   trunk/varnish-cache/bin/varnishd/cache_esi_parse.c
Log:
Munge the esi:include src attribute as required, to produce URL and
Host: header.

Correctly unpack Host: header in esi delivery.

Now e00008.vtc is the first case to fail.



Modified: trunk/varnish-cache/bin/varnishd/cache_esi_deliver.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi_deliver.c	2011-01-13 11:12:06 UTC (rev 5729)
+++ trunk/varnish-cache/bin/varnishd/cache_esi_deliver.c	2011-01-13 11:55:11 UTC (rev 5730)
@@ -72,7 +72,7 @@
 	ws_wm = WS_Snapshot(sp->ws);
 
 	http_SetH(sp->http, HTTP_HDR_URL, src);
-	if (host != NULL)  {
+	if (host != NULL && *host != '\0')  {
 		http_Unset(sp->http, H_Host);
 		http_Unset(sp->http, H_If_Modified_Since);
 		http_SetHeader(w, sp->fd, sp->http, host);
@@ -125,7 +125,7 @@
 ESI_Deliver(struct sess *sp)
 {
 	struct storage *st;
-	uint8_t *p, *e, *q;
+	uint8_t *p, *e, *q, *r;
 	unsigned off;
 	size_t l;
 
@@ -140,6 +140,8 @@
 	off = 0;
 
 	while (p < e) {
+		//usleep(10000);
+		//WRW_Flush(sp->wrk);
 		switch (*p) {
 		case VEC_V1:
 			l = p[1];
@@ -179,9 +181,14 @@
 		case VEC_INCL:
 			p++;
 			q = (void*)strchr((const char*)p, '\0');
-			printf("INCL [%s]\n", p);
-			ESI_Include(sp, (const char*)p, NULL);
-			p = q + 1;
+			AN(q);
+			q++;
+			r = (void*)strchr((const char*)q, '\0');
+			AN(r);
+			printf("INCL [%s][%s] BEGIN\n", p, q);
+			ESI_Include(sp, (const char*)p, (const char*)q);
+			printf("INCL [%s] END\n", p);
+			p = r + 1;
 			break;
 		default:
 			printf("XXXX %02x [%c]\n", *p, *p);
@@ -189,6 +196,7 @@
 			return;
 		}
 	}
+printf("DONE\n");
 	WRW_Flush(sp->wrk);
 }
 

Modified: trunk/varnish-cache/bin/varnishd/cache_esi_parse.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi_parse.c	2011-01-13 11:12:06 UTC (rev 5729)
+++ trunk/varnish-cache/bin/varnishd/cache_esi_parse.c	2011-01-13 11:55:11 UTC (rev 5730)
@@ -59,6 +59,8 @@
 	vfp_bytes_f		*bytes;
 	struct vsb		*vsb;
 
+	struct sess		*sp;
+
 	/* parser state */
 	const char		*state;
 
@@ -324,6 +326,9 @@
 static void
 vep_do_include(struct vep_state *vep, enum dowhat what)
 {
+	char *p, *q, *h;
+	ssize_t l;
+	txt url;
 
 	printf("DO_INCLUDE(%d)\n", what);
 	if (what == DO_ATTR) {
@@ -338,10 +343,39 @@
 		if (vep->o_verbatim > 0) 
 			vep_emit_verbatim(vep);
 		/* XXX: what if it contains NUL bytes ?? */
-		vsb_printf(vep->vsb, "%c%s%c",
-		    VEC_INCL,
-		    vsb_data(vep->include_src), 0);
+		p = vsb_data(vep->include_src);
+		l = vsb_len(vep->include_src);
+		h = 0;
 
+		if (l > 7 && !memcmp(p, "http://", 7)) {
+			h = p + 7;
+			p = strchr(h, '/');
+			AN(p);
+			printf("HOST <%.*s> PATH <%s>\n", (int)(p-h),h, p);
+			vsb_printf(vep->vsb, "%c%s%cHost: %.*s%c",
+			    VEC_INCL, p, 0,
+			    (int)(p-h), h, 0);
+		} else if (*p == '/') {
+			vsb_printf(vep->vsb, "%c%s%c%c",
+			    VEC_INCL, p, 0, 0);
+		} else {
+			url = vep->sp->wrk->bereq->hd[HTTP_HDR_URL];
+			/* Look for the last / before a '?' */
+			h = NULL;
+			for (q = url.b; q < url.e && *q != '?'; q++)
+				if (*q == '/')
+					h = q;
+			if (h == NULL)
+				h = q + 1;
+				
+			printf("INCL:: %.*s/%s\n",
+			    (int)(h - url.b), url.b, p);
+			vsb_printf(vep->vsb, "%c%.*s/%s%c%c",
+			    VEC_INCL, 
+			    (int)(h - url.b), url.b,
+			    p, 0, 0);
+		}
+
 		vsb_delete(vep->include_src);
 		vep->include_src = NULL;
 	}
@@ -373,12 +407,15 @@
 	p = b;
 	while (p < e) {
 		AN(vep->state);
+		i = e - p;
+		if (i > 10)
+			i = 10;
 		printf("EP %s %d %d (%.*s) [%.*s]\n",
 		    vep->state,
 		    vep->skip,
 		    vep->remove,
 		    vep->tag_i, vep->tag,
-		    (int)(e - p), p);
+		    i, p);
 		fflush(stdout);
 		usleep(10);
 
@@ -415,13 +452,13 @@
 		} else if (vep->state == VEP_NOTMYTAG) {
 			vep->tag_i = 0;
 			while (p < e) {
-				if (!vep->remove)
-					vep_mark_verbatim(vep, p + 1);
 				if (*p++ == '>') {
 					vep->state = VEP_NEXTTAG;
 					break;
 				}
 			}
+			if (!vep->remove)
+				vep_mark_verbatim(vep, p + 1);
 		} else if (vep->state == VEP_NEXTTAG) {
 			/*
 			 * Hunt for start of next tag and keep an eye
@@ -447,11 +484,10 @@
 				} else {
 					p++;
 					vep->esicmt_p = vep->esicmt;
-					if (vep->esicmt_p == NULL &&
-					    !vep->remove)
-						vep_mark_verbatim(vep, p);
 				}
 			}
+			if (vep->esicmt_p == NULL && !vep->remove)
+				vep_mark_verbatim(vep, p);
 			if (p < e)
 				vep->state = VEP_STARTTAG;
 
@@ -507,13 +543,13 @@
 			if (vep->remove) {
 				VSC_main->esi_errors++;
 				vep->state = VEP_NOTMYTAG;
-				break;
+			} else {
+				vep->skip = 1;
+				vep_mark_skip(vep, p);
+				vep->match = vep_match_esi;
+				vep->match_l = vep_match_esi_len;
+				vep->state = VEP_MATCH;
 			}
-			vep->skip = 1;
-			vep_mark_skip(vep, p);
-			vep->match = vep_match_esi;
-			vep->match_l = vep_match_esi_len;
-			vep->state = VEP_MATCH;
 		} else if (vep->state == VEP_ESIETAG) {
 			vep->tag_i = 0;
 			vep->endtag = 1;
@@ -528,6 +564,7 @@
 		} else if (vep->state == VEP_ESIREMOVE) {
 			vep->dostuff = vep_do_nothing;
 			vep->remove = !vep->endtag;
+printf(">>> REMOVE %d\n", vep->remove);
 			vep->state = VEP_INTAG;
 
 		/******************************************************
@@ -754,6 +791,7 @@
 
 	memset(vep, 0, sizeof *vep);
 	vep->magic = VEP_MAGIC;
+	vep->sp = sp;
 	vep->bytes = vfp_esi_bytes_uu;
 	vep->vsb = vsb_newauto();
 	vep->state = VEP_START;




More information about the varnish-commit mailing list