r69 - in trunk/varnish-cache: bin/varnishd include

phk at projects.linpro.no phk at projects.linpro.no
Fri Mar 24 11:46:46 CET 2006


Author: phk
Date: 2006-03-24 11:46:46 +0100 (Fri, 24 Mar 2006)
New Revision: 69

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/bin/varnishd/cache_httpd.c
   trunk/varnish-cache/include/shmlog_tags.h
Log:
More complete HTTP parsing and logging.


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-03-24 10:23:43 UTC (rev 68)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-03-24 10:46:46 UTC (rev 69)
@@ -4,11 +4,34 @@
 
 #define VCA_RXBUFSIZE		1024
 #define VCA_ADDRBUFSIZE		32
+
 struct sess {
 	int		fd;
+
+	/* formatted ascii client address */
+	char		addr[VCA_ADDRBUFSIZE];
+
+	/* Receive buffer for HTTP header */
 	char		rcv[VCA_RXBUFSIZE + 1];
-	char		addr[VCA_ADDRBUFSIZE];
 	unsigned	rcv_len;
+
+	/* HTTP request info, points into rcv */
+	const char	*req_b;
+	const char	*req_e;
+	const char	*url_b;
+	const char	*url_e;
+	const char	*proto_b;
+	const char	*proto_e;
+	const char	*hdr_b;
+	const char	*hdr_e;
+
+	enum {
+		HND_Unclass,
+		HND_Handle,
+		HND_Pass
+	}		handling;
+
+	/* Various internal stuff */
 	struct event	*rd_e;
 	struct sessmem	*mem;
 };

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-03-24 10:23:43 UTC (rev 68)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-03-24 10:46:46 UTC (rev 69)
@@ -64,9 +64,9 @@
 			continue;
 		break;
 	}
+	sp->hdr_e = p;
 	event_del(sp->rd_e);
 	HttpdAnalyze(sp);
-	printf("full <%s>\n", sp->rcv);
 }
 
 static void

Modified: trunk/varnish-cache/bin/varnishd/cache_httpd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_httpd.c	2006-03-24 10:23:43 UTC (rev 68)
+++ trunk/varnish-cache/bin/varnishd/cache_httpd.c	2006-03-24 10:46:46 UTC (rev 69)
@@ -14,27 +14,60 @@
 void
 HttpdAnalyze(struct sess *sp)
 {
-	const char *p, *q, *u;
+	const char *p, *q;
 
-	p = sp->rcv;
+	sp->handling = HND_Unclass;
 
+	/* First, isolate and possibly identify request type */
+	p = sp->req_b = sp->rcv;
 	if (p[0] == 'G' && p[1] == 'E' && p[2] == 'T' && p[3] == ' ') {
-		p += 4;
-		VSL(SLT_Request, sp->fd, "GET");
+		p = sp->req_e = p + 4;
+		sp->handling = HND_Handle;
 	} else if (p[0] == 'H' && p[1] == 'E' && p[2] == 'A' && p[3] == 'D'
 	    && p[4] == ' ') {
-		p += 5;
-		VSL(SLT_Request, sp->fd, "HEAD");
+		p = sp->req_e = p + 5;
+		sp->handling = HND_Handle;
 	} else {
-		for (q = p; isupper(*q); q++)
+		/*
+		 * We don't bother to identify the rest, we won't handle
+		 * them in any case
+		 */
+		for (q = p; isalpha(*q); q++)
 			;
-		VSLR(SLT_Request, sp->fd, p, q);
-		p = q;
+		p = sp->req_e = q;
+		sp->handling = HND_Pass;
 	}
+	VSLR(SLT_Request, sp->fd, sp->req_b, sp->req_e);
+
+	/* Next find the URI */
 	while (isspace(*p))
 		p++;
-	u = p;
+	sp->url_b = p;
 	while (!isspace(*p))
 		p++;
-	VSLR(SLT_URL, sp->fd, u, p);
+	sp->url_e = p;
+	VSLR(SLT_URL, sp->fd, sp->url_b, sp->url_e);
+
+	/* Finally, look for protocol, if any */
+	while (isspace(*p) && *p != '\n')
+		p++;
+	sp->proto_b = sp->proto_e = p;
+	if (*p != '\n') {
+		while (!isspace(*p))
+			p++;
+		sp->proto_e = p;
+	}
+	VSLR(SLT_Protocol, sp->fd, sp->proto_b, sp->proto_e);
+
+	/*
+	 * And mark the start of headers.  The end of headers 
+	 * is already set in acceptor where we detected the complete request.
+	 */
+	while (*p != '\n')
+		p++;
+	p++;
+	while (isspace(*p) && *p != '\n')
+		p++;
+	sp->hdr_b = p;
+	VSLR(SLT_Headers, sp->fd, sp->hdr_b, sp->hdr_e);
 }

Modified: trunk/varnish-cache/include/shmlog_tags.h
===================================================================
--- trunk/varnish-cache/include/shmlog_tags.h	2006-03-24 10:23:43 UTC (rev 68)
+++ trunk/varnish-cache/include/shmlog_tags.h	2006-03-24 10:46:46 UTC (rev 69)
@@ -13,3 +13,4 @@
 SLTM(Request)
 SLTM(URL)
 SLTM(Protocol)
+SLTM(Headers)




More information about the varnish-commit mailing list