r97 - in trunk/varnish-cache: bin/varnishd include lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Mon Apr 3 13:05:53 CEST 2006


Author: phk
Date: 2006-04-03 13:05:53 +0200 (Mon, 03 Apr 2006)
New Revision: 97

Modified:
   trunk/varnish-cache/bin/varnishd/cache_backend.c
   trunk/varnish-cache/bin/varnishd/cache_httpd.c
   trunk/varnish-cache/bin/varnishd/cache_pipe.c
   trunk/varnish-cache/include/shmlog_tags.h
   trunk/varnish-cache/include/vcl_lang.h
   trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c
Log:
Segregate http header fields into a separate structure, we will
reuse them a few places by the looks of it.

Add VCA_UNKNOWNHDR (=10) fields for unknown HTTP headers.
If more headers arrive than that, they're lost (and logged as such).




Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2006-04-03 11:03:28 UTC (rev 96)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2006-04-03 11:05:53 UTC (rev 97)
@@ -152,17 +152,17 @@
 
 	sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
 	assert(sb != NULL);
-	sbuf_cat(sb, sp->req);
+	sbuf_cat(sb, sp->http.req);
 	sbuf_cat(sb, " ");
-	sbuf_cat(sb, sp->url);
+	sbuf_cat(sb, sp->http.url);
 	sbuf_cat(sb, " ");
-	sbuf_cat(sb, sp->proto);
+	sbuf_cat(sb, sp->http.proto);
 	sbuf_cat(sb, "\r\n");
 #define HTTPH(a, b, c, d, e, f, g) 				\
 	do {							\
-		if (c && sp->b != NULL) {			\
+		if (c && sp->http.b != NULL) {			\
 			sbuf_cat(sb, a ": ");			\
-			sbuf_cat(sb, sp->b);			\
+			sbuf_cat(sb, sp->http.b);		\
 			sbuf_cat(sb, "\r\n");			\
 		}						\
 	} while (0);

Modified: trunk/varnish-cache/bin/varnishd/cache_httpd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_httpd.c	2006-04-03 11:03:28 UTC (rev 96)
+++ trunk/varnish-cache/bin/varnishd/cache_httpd.c	2006-04-03 11:05:53 UTC (rev 97)
@@ -22,30 +22,30 @@
 	sp->handling = HND_Unclass;
 
 	/* First, isolate and possibly identify request type */
-	sp->req = sp->rcv;
+	sp->http.req = sp->rcv;
 	for (p = sp->rcv; isalpha(*p); p++)
 		;
-	VSLR(SLT_Request, sp->fd, sp->req, p);
+	VSLR(SLT_Request, sp->fd, sp->http.req, p);
 	*p++ = '\0';
 
 	/* Next find the URI */
 	while (isspace(*p))
 		p++;
-	sp->url = p;
+	sp->http.url = p;
 	while (!isspace(*p))
 		p++;
-	VSLR(SLT_URL, sp->fd, sp->url, p);
+	VSLR(SLT_URL, sp->fd, sp->http.url, p);
 	*p++ = '\0';
 
 	/* Finally, look for protocol, if any */
 	while (isspace(*p) && *p != '\n')
 		p++;
-	sp->proto = p;
+	sp->http.proto = p;
 	if (*p != '\n') {
 		while (!isspace(*p))
 			p++;
 	}
-	VSLR(SLT_Protocol, sp->fd, sp->proto, p);
+	VSLR(SLT_Protocol, sp->fd, sp->http.proto, p);
 	*p++ = '\0';
 
 	while (isspace(*p) && *p != '\n')
@@ -55,9 +55,7 @@
 	if (*p == '\r')
 		p++;
 
-#define HTTPH(a, b, c, d, e, f, g)	sp->b = NULL;
-#include "http_headers.h"
-#undef HTTPH
+	memset(&sp->http, 0, sizeof sp->http);
 
 	for (; p < sp->rcv + sp->rcv_len; p = r) {
 		q = strchr(p, '\n');
@@ -72,7 +70,7 @@
     if (!strncasecmp(p, a, strlen(a))) {		\
 	for (p += strlen(a); p < q && isspace(*p); p++) \
 		continue;				\
-	sp->b = p;					\
+	sp->http.b = p;					\
 	VSLR(SLT_##b, sp->fd, p, q);			\
 	continue;					\
     } 
@@ -81,7 +79,11 @@
 #include "http_headers.h"
 #undef HTTPH
 #undef W
-		VSLR(SLT_H_Unknown, sp->fd, p, q);
+		if (sp->http.nuhdr < VCA_UNKNOWNHDR) {
+			sp->http.uhdr[sp->http.nuhdr++] = p;
+			VSLR(SLT_HD_Unknown, sp->fd, p, q);
+		} else {
+			VSLR(SLT_HD_Lost, sp->fd, p, q);
+		}
 	}
-
 }

Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pipe.c	2006-04-03 11:03:28 UTC (rev 96)
+++ trunk/varnish-cache/bin/varnishd/cache_pipe.c	2006-04-03 11:05:53 UTC (rev 97)
@@ -55,19 +55,19 @@
 
 	sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
 	assert(sb != NULL);
-	sbuf_cat(sb, sp->req);
+	sbuf_cat(sb, sp->http.req);
 	sbuf_cat(sb, " ");
-	sbuf_cat(sb, sp->url);
-	if (sp->proto != NULL) {
+	sbuf_cat(sb, sp->http.url);
+	if (sp->http.proto != NULL) {
 		sbuf_cat(sb, " ");
-		sbuf_cat(sb, sp->proto);
+		sbuf_cat(sb, sp->http.proto);
 	}
 	sbuf_cat(sb, "\r\n");
 #define HTTPH(a, b, c, d, e, f, g) 				\
 	do {							\
-		if (sp->b != NULL) {				\
+		if (sp->http.b != NULL) {			\
 			sbuf_cat(sb, a ": ");			\
-			sbuf_cat(sb, sp->b);			\
+			sbuf_cat(sb, sp->http.b);		\
 			sbuf_cat(sb, "\r\n");			\
 		}						\
 	} while (0);

Modified: trunk/varnish-cache/include/shmlog_tags.h
===================================================================
--- trunk/varnish-cache/include/shmlog_tags.h	2006-04-03 11:03:28 UTC (rev 96)
+++ trunk/varnish-cache/include/shmlog_tags.h	2006-04-03 11:05:53 UTC (rev 97)
@@ -13,7 +13,8 @@
 SLTM(Request)
 SLTM(URL)
 SLTM(Protocol)
-SLTM(H_Unknown)
+SLTM(HD_Unknown)
+SLTM(HD_Lost)
 #define HTTPH(a, b, c, d, e, f, g)	SLTM(b)
 #include "http_headers.h"
 #undef HTTPH

Modified: trunk/varnish-cache/include/vcl_lang.h
===================================================================
--- trunk/varnish-cache/include/vcl_lang.h	2006-04-03 11:03:28 UTC (rev 96)
+++ trunk/varnish-cache/include/vcl_lang.h	2006-04-03 11:05:53 UTC (rev 97)
@@ -22,7 +22,19 @@
 
 #define VCA_RXBUFSIZE		1024
 #define VCA_ADDRBUFSIZE		32
+#define VCA_UNKNOWNHDR		10
 
+struct httphdr {
+	const char		*req;
+	const char		*url;
+	const char		*proto;
+#define HTTPH(a, b, c, d, e, f, g) const char *b;
+#include <http_headers.h>
+#undef HTTPH
+	const char		*uhdr[VCA_UNKNOWNHDR];
+	unsigned		nuhdr;
+};
+
 struct sess {
 	int			fd;
 
@@ -34,12 +46,7 @@
 	unsigned		rcv_len;
 
 	/* HTTP request info, points into rcv */
-	const char		*req;
-	const char		*url;
-	const char		*proto;
-#define HTTPH(a, b, c, d, e, f, g) const char *b;
-#include <http_headers.h>
-#undef HTTPH
+	struct httphdr		http;
 
 	enum {
 		HND_Unclass,

Modified: trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c	2006-04-03 11:03:28 UTC (rev 96)
+++ trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c	2006-04-03 11:05:53 UTC (rev 97)
@@ -403,18 +403,9 @@
 	fputs("\n", f);
 	fputs("#define VCA_RXBUFSIZE		1024\n", f);
 	fputs("#define VCA_ADDRBUFSIZE		32\n", f);
+	fputs("#define VCA_UNKNOWNHDR		10\n", f);
 	fputs("\n", f);
-	fputs("struct sess {\n", f);
-	fputs("	int			fd;\n", f);
-	fputs("\n", f);
-	fputs("	/* formatted ascii client address */\n", f);
-	fputs("	char			addr[VCA_ADDRBUFSIZE];\n", f);
-	fputs("\n", f);
-	fputs("	/* Receive buffer for HTTP header */\n", f);
-	fputs("	char			rcv[VCA_RXBUFSIZE + 1];\n", f);
-	fputs("	unsigned		rcv_len;\n", f);
-	fputs("\n", f);
-	fputs("	/* HTTP request info, points into rcv */\n", f);
+	fputs("struct httphdr {\n", f);
 	fputs("	const char		*req;\n", f);
 	fputs("	const char		*url;\n", f);
 	fputs("	const char		*proto;\n", f);
@@ -455,7 +446,23 @@
 	fputs("HTTPH(\"TE\",			H_TE,			0, 0, 0, 0, 0)\n", f);
 	fputs("HTTPH(\"User-Agent\",		H_User_Agent,		1, 0, 0, 0, 0)\n", f);
 	fputs("#undef HTTPH\n", f);
+	fputs("	const char		*uhdr[VCA_UNKNOWNHDR];\n", f);
+	fputs("	unsigned		nuhdr;\n", f);
+	fputs("};\n", f);
 	fputs("\n", f);
+	fputs("struct sess {\n", f);
+	fputs("	int			fd;\n", f);
+	fputs("\n", f);
+	fputs("	/* formatted ascii client address */\n", f);
+	fputs("	char			addr[VCA_ADDRBUFSIZE];\n", f);
+	fputs("\n", f);
+	fputs("	/* Receive buffer for HTTP header */\n", f);
+	fputs("	char			rcv[VCA_RXBUFSIZE + 1];\n", f);
+	fputs("	unsigned		rcv_len;\n", f);
+	fputs("\n", f);
+	fputs("	/* HTTP request info, points into rcv */\n", f);
+	fputs("	struct httphdr		http;\n", f);
+	fputs("\n", f);
 	fputs("	enum {\n", f);
 	fputs("		HND_Unclass,\n", f);
 	fputs("		HND_Handle,\n", f);




More information about the varnish-commit mailing list