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

phk at projects.linpro.no phk at projects.linpro.no
Tue Apr 4 10:20:24 CEST 2006


Author: phk
Date: 2006-04-04 10:20:24 +0200 (Tue, 04 Apr 2006)
New Revision: 111

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_httpd.c
   trunk/varnish-cache/bin/varnishd/cache_pass.c
   trunk/varnish-cache/bin/varnishd/cache_pipe.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/include/http_headers.h
   trunk/varnish-cache/include/shmlog_tags.h
   trunk/varnish-cache/include/vcl_lang.h
   trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c
Log:
Add HTTP response headers and processing.


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-04-04 07:46:30 UTC (rev 110)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-04-04 08:20:24 UTC (rev 111)
@@ -15,7 +15,7 @@
 void VBE_ClosedFd(void *ptr);
 
 /* cache_httpd.c */
-void HttpdAnalyze(struct sess *sp);
+void HttpdAnalyze(struct sess *sp, int rr);
 void HttpdGetHead(struct sess *sp, struct event_base *eb, sesscb_f *func);
 
 /* cache_main.c */

Modified: trunk/varnish-cache/bin/varnishd/cache_httpd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_httpd.c	2006-04-04 07:46:30 UTC (rev 110)
+++ trunk/varnish-cache/bin/varnishd/cache_httpd.c	2006-04-04 08:20:24 UTC (rev 111)
@@ -21,7 +21,7 @@
 /*--------------------------------------------------------------------*/
 
 void
-HttpdAnalyze(struct sess *sp)
+HttpdAnalyze(struct sess *sp, int rr)
 {
 	char *p, *q, *r;
 
@@ -29,37 +29,68 @@
 
 	memset(&sp->http, 0, sizeof sp->http);
 
-	/* First, isolate and possibly identify request type */
-	sp->http.req = sp->rcv;
-	for (p = sp->rcv; isalpha(*p); p++)
-		;
-	VSLR(SLT_Request, sp->fd, sp->http.req, p);
-	*p++ = '\0';
+	if (rr == 1) {
+		/* First, isolate and possibly identify request type */
+		sp->http.req = sp->rcv;
+		for (p = sp->rcv; isalpha(*p); p++)
+			;
+		VSLR(SLT_Request, sp->fd, sp->http.req, p);
+		*p++ = '\0';
 
-	/* Next find the URI */
-	while (isspace(*p))
-		p++;
-	sp->http.url = p;
-	while (!isspace(*p))
-		p++;
-	VSLR(SLT_URL, sp->fd, sp->http.url, p);
-	*p++ = '\0';
+		/* Next find the URI */
+		while (isspace(*p))
+			p++;
+		sp->http.url = p;
+		while (!isspace(*p))
+			p++;
+		VSLR(SLT_URL, sp->fd, sp->http.url, p);
+		*p++ = '\0';
 
-	/* Finally, look for protocol, if any */
-	while (isspace(*p) && *p != '\n')
+		/* Finally, look for protocol, if any */
+		while (isspace(*p) && *p != '\n')
+			p++;
+		sp->http.proto = p;
+		if (*p != '\n') {
+			while (!isspace(*p))
+				p++;
+		}
+		VSLR(SLT_Protocol, sp->fd, sp->http.proto, p);
+		*p++ = '\0';
+
+		while (isspace(*p) && *p != '\n')
+			p++;
 		p++;
-	sp->http.proto = p;
-	if (*p != '\n') {
+	} else {
+		/* First, protocol */
+		sp->http.proto = sp->rcv;
+		p = sp->rcv;
 		while (!isspace(*p))
 			p++;
-	}
-	VSLR(SLT_Protocol, sp->fd, sp->http.proto, p);
-	*p++ = '\0';
+		*p++ = '\0';
+		VSLR(SLT_Protocol, sp->fd, sp->http.proto, p);
 
-	while (isspace(*p) && *p != '\n')
+		/* Next find the status */
+		while (isspace(*p))
+			p++;
+		sp->http.status = p;
+		while (!isspace(*p))
+			p++;
+		VSLR(SLT_Status, sp->fd, sp->http.status, p);
+		*p++ = '\0';
+
+		/* Next find the response */
+		while (isspace(*p))
+			p++;
+		sp->http.response = p;
+		while (*p != '\n')
+			p++;
+		for (q = p; q > sp->http.response && isspace(q[-1]); q--)
+			continue;
+		*q = '\0';
+		VSLR(SLT_Response, sp->fd, sp->http.response, q);
 		p++;
+	}
 
-	p++;
 	if (*p == '\r')
 		p++;
 
@@ -81,7 +112,10 @@
 	continue;					\
     } 
 
-#define HTTPH(a, b, c, d, e, f, g)	W(a ":", b, p, q, sp)
+#define HTTPH(a, b, c, d, e, f, g)			\
+	if (c & rr) {					\
+		W(a ":", b, p, q, sp);			\
+	}
 #include "http_headers.h"
 #undef HTTPH
 #undef W

Modified: trunk/varnish-cache/bin/varnishd/cache_pass.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pass.c	2006-04-04 07:46:30 UTC (rev 110)
+++ trunk/varnish-cache/bin/varnishd/cache_pass.c	2006-04-04 08:20:24 UTC (rev 111)
@@ -25,7 +25,7 @@
 {
 
 	HERE();
-	HttpdAnalyze(sp);
+	HttpdAnalyze(sp, 2);
 }
 
 /*--------------------------------------------------------------------*/
@@ -52,7 +52,7 @@
 	sbuf_cat(sb, "\r\n");
 #define HTTPH(a, b, c, d, e, f, g) 				\
 	do {							\
-		if (c && sp->http.b != NULL) {			\
+		if (d && sp->http.b != NULL) {			\
 			sbuf_cat(sb, a ": ");			\
 			sbuf_cat(sb, sp->http.b);		\
 			sbuf_cat(sb, "\r\n");			\
@@ -62,7 +62,6 @@
 #undef HTTPH
 	sbuf_cat(sb, "\r\n");
 	sbuf_finish(sb);
-	printf("REQ: <%s>\n", sbuf_data(sb));
 	i = write(fd, sbuf_data(sb), sbuf_len(sb));
 	assert(i == sbuf_len(sb));
 

Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pipe.c	2006-04-04 07:46:30 UTC (rev 110)
+++ trunk/varnish-cache/bin/varnishd/cache_pipe.c	2006-04-04 08:20:24 UTC (rev 111)
@@ -75,7 +75,6 @@
 #undef HTTPH
 	sbuf_cat(sb, "\r\n");
 	sbuf_finish(sb);
-	printf("REQ: <%s>\n", sbuf_data(sb));
 	i = write(fd, sbuf_data(sb), sbuf_len(sb));
 	assert(i == sbuf_len(sb));
 

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-04-04 07:46:30 UTC (rev 110)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-04-04 08:20:24 UTC (rev 111)
@@ -31,7 +31,7 @@
 		sp->vcl = GetVCL();
 		AZ(pthread_mutex_unlock(&sessmtx));
 
-		HttpdAnalyze(sp);
+		HttpdAnalyze(sp, 1);
 
 		sp->backend = sp->vcl->default_backend;
 		/* Call the VCL program */

Modified: trunk/varnish-cache/include/http_headers.h
===================================================================
--- trunk/varnish-cache/include/http_headers.h	2006-04-04 07:46:30 UTC (rev 110)
+++ trunk/varnish-cache/include/http_headers.h	2006-04-04 08:20:24 UTC (rev 111)
@@ -3,8 +3,8 @@
  *
  * a	Http header name
  * b	session field name
- * c	PassThrough handling (0=remove, 1=pass)
- * d	unused
+ * c	Request(1)/Response(2) bitfield
+ * d	Pass header
  * e	unused
  * f	unused
  * g	unused
@@ -12,24 +12,35 @@
  *    a                         b                       c  d  e  f  g 
  *--------------------------------------------------------------------
  */
-HTTPH("Accept-Charset",		H_Accept_Charset,	1, 0, 0, 0, 0)
-HTTPH("Accept-Encoding",	H_Accept_Encoding,	1, 0, 0, 0, 0)
-HTTPH("Accept-Language",	H_Accept_Language,	1, 0, 0, 0, 0)
-HTTPH("Accept",			H_Accept,		1, 0, 0, 0, 0)
-HTTPH("Authorization",		H_Authorization,	1, 0, 0, 0, 0)
-HTTPH("Connection",		H_Connection,		0, 0, 0, 0, 0)
-HTTPH("Expect",			H_Expect,		1, 0, 0, 0, 0)
-HTTPH("From",			H_From,			1, 0, 0, 0, 0)
-HTTPH("Host",			H_Host,			1, 0, 0, 0, 0)
-HTTPH("If-Match",		H_If_Match,		1, 0, 0, 0, 0)
-HTTPH("If-Modified-Since",	H_If_Modified_Since,	1, 0, 0, 0, 0)
-HTTPH("If-None-Match",		H_If_None_Match,	1, 0, 0, 0, 0)
-HTTPH("If-Range",		H_If_Range,		1, 0, 0, 0, 0)
-HTTPH("If-Unmodified-Since",	H_If_Unmodifed_Since,	1, 0, 0, 0, 0)
-HTTPH("Keep-Alive",		H_Keep_Alive,		0, 0, 0, 0, 0)
-HTTPH("Max-Forwards",		H_Max_Forwards,		1, 0, 0, 0, 0)
-HTTPH("Proxy-Authorization",	H_Proxy_Authorization,	1, 0, 0, 0, 0)
-HTTPH("Range",			H_Range,		1, 0, 0, 0, 0)
-HTTPH("Referer",		H_Referer,		1, 0, 0, 0, 0)
-HTTPH("TE",			H_TE,			1, 0, 0, 0, 0)
-HTTPH("User-Agent",		H_User_Agent,		1, 0, 0, 0, 0)
+HTTPH("Connection",		H_Connection,		3, 0, 0, 0, 0)
+HTTPH("Keep-Alive",		H_Keep_Alive,		3, 0, 0, 0, 0)
+
+HTTPH("Accept-Charset",		H_Accept_Charset,	1, 1, 0, 0, 0)
+HTTPH("Accept-Encoding",	H_Accept_Encoding,	1, 1, 0, 0, 0)
+HTTPH("Accept-Language",	H_Accept_Language,	1, 1, 0, 0, 0)
+HTTPH("Accept",			H_Accept,		1, 1, 0, 0, 0)
+HTTPH("Authorization",		H_Authorization,	1, 1, 0, 0, 0)
+HTTPH("Expect",			H_Expect,		1, 1, 0, 0, 0)
+HTTPH("From",			H_From,			1, 1, 0, 0, 0)
+HTTPH("Host",			H_Host,			1, 1, 0, 0, 0)
+HTTPH("If-Match",		H_If_Match,		1, 1, 0, 0, 0)
+HTTPH("If-Modified-Since",	H_If_Modified_Since,	1, 1, 0, 0, 0)
+HTTPH("If-None-Match",		H_If_None_Match,	1, 1, 0, 0, 0)
+HTTPH("If-Range",		H_If_Range,		1, 1, 0, 0, 0)
+HTTPH("If-Unmodified-Since",	H_If_Unmodifed_Since,	1, 1, 0, 0, 0)
+HTTPH("Max-Forwards",		H_Max_Forwards,		1, 1, 0, 0, 0)
+HTTPH("Proxy-Authorization",	H_Proxy_Authorization,	1, 1, 0, 0, 0)
+HTTPH("Range",			H_Range,		1, 1, 0, 0, 0)
+HTTPH("Referer",		H_Referer,		1, 1, 0, 0, 0)
+HTTPH("TE",			H_TE,			1, 1, 0, 0, 0)
+HTTPH("User-Agent",		H_User_Agent,		1, 1, 0, 0, 0)
+
+HTTPH("Server",			H_Server,		2, 0, 0, 0, 0)
+HTTPH("Content-Type",		H_Content_Type,		2, 0, 0, 0, 0)
+HTTPH("Date",			H_Date,			2, 0, 0, 0, 0)
+HTTPH("Last-Modified",		H_Last_Modified,	2, 0, 0, 0, 0)
+HTTPH("Accept-Ranges",		H_Accept_Ranges,	2, 0, 0, 0, 0)
+HTTPH("Content-Length",		H_Content_Length,	2, 0, 0, 0, 0)
+HTTPH("Cache-Control",		H_Cache_Control,	2, 0, 0, 0, 0)
+HTTPH("Vary",			H_Vary,			2, 0, 0, 0, 0)
+HTTPH("Expires",		H_Expires,		2, 0, 0, 0, 0)

Modified: trunk/varnish-cache/include/shmlog_tags.h
===================================================================
--- trunk/varnish-cache/include/shmlog_tags.h	2006-04-04 07:46:30 UTC (rev 110)
+++ trunk/varnish-cache/include/shmlog_tags.h	2006-04-04 08:20:24 UTC (rev 111)
@@ -12,6 +12,8 @@
 SLTM(SessionClose)
 SLTM(ClientAddr)
 SLTM(Request)
+SLTM(Response)
+SLTM(Status)
 SLTM(URL)
 SLTM(Protocol)
 SLTM(HD_Unknown)

Modified: trunk/varnish-cache/include/vcl_lang.h
===================================================================
--- trunk/varnish-cache/include/vcl_lang.h	2006-04-04 07:46:30 UTC (rev 110)
+++ trunk/varnish-cache/include/vcl_lang.h	2006-04-04 08:20:24 UTC (rev 111)
@@ -31,6 +31,8 @@
 	const char		*req;
 	const char		*url;
 	const char		*proto;
+	const char		*status;
+	const char		*response;
 #define HTTPH(a, b, c, d, e, f, g) const char *b;
 #include <http_headers.h>
 #undef HTTPH

Modified: trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c	2006-04-04 07:46:30 UTC (rev 110)
+++ trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c	2006-04-04 08:20:24 UTC (rev 111)
@@ -412,14 +412,16 @@
 	fputs("	const char		*req;\n", f);
 	fputs("	const char		*url;\n", f);
 	fputs("	const char		*proto;\n", f);
+	fputs("	const char		*status;\n", f);
+	fputs("	const char		*response;\n", f);
 	fputs("#define HTTPH(a, b, c, d, e, f, g) const char *b;\n", f);
 	fputs("/*\n", f);
 	fputs(" * $Id$\n", f);
 	fputs(" *\n", f);
 	fputs(" * a	Http header name\n", f);
 	fputs(" * b	session field name\n", f);
-	fputs(" * c	PassThrough handling (0=remove, 1=pass)\n", f);
-	fputs(" * d	unused\n", f);
+	fputs(" * c	Request(1)/Response(2) bitfield\n", f);
+	fputs(" * d	Pass header\n", f);
 	fputs(" * e	unused\n", f);
 	fputs(" * f	unused\n", f);
 	fputs(" * g	unused\n", f);
@@ -427,27 +429,38 @@
 	fputs(" *    a                         b                       c  d  e  f  g \n", f);
 	fputs(" *--------------------------------------------------------------------\n", f);
 	fputs(" */\n", f);
-	fputs("HTTPH(\"Accept-Charset\",		H_Accept_Charset,	1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"Accept-Encoding\",	H_Accept_Encoding,	1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"Accept-Language\",	H_Accept_Language,	1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"Accept\",			H_Accept,		1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"Authorization\",		H_Authorization,	1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"Connection\",		H_Connection,		0, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"Expect\",			H_Expect,		1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"From\",			H_From,			1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"Host\",			H_Host,			1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"If-Match\",		H_If_Match,		1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"If-Modified-Since\",	H_If_Modified_Since,	1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"If-None-Match\",		H_If_None_Match,	1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"If-Range\",		H_If_Range,		1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"If-Unmodified-Since\",	H_If_Unmodifed_Since,	1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"Keep-Alive\",		H_Keep_Alive,		0, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"Max-Forwards\",		H_Max_Forwards,		1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"Proxy-Authorization\",	H_Proxy_Authorization,	1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"Range\",			H_Range,		1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"Referer\",		H_Referer,		1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"TE\",			H_TE,			1, 0, 0, 0, 0)\n", f);
-	fputs("HTTPH(\"User-Agent\",		H_User_Agent,		1, 0, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Connection\",		H_Connection,		3, 0, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Keep-Alive\",		H_Keep_Alive,		3, 0, 0, 0, 0)\n", f);
+	fputs("\n", f);
+	fputs("HTTPH(\"Accept-Charset\",		H_Accept_Charset,	1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Accept-Encoding\",	H_Accept_Encoding,	1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Accept-Language\",	H_Accept_Language,	1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Accept\",			H_Accept,		1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Authorization\",		H_Authorization,	1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Expect\",			H_Expect,		1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"From\",			H_From,			1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Host\",			H_Host,			1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"If-Match\",		H_If_Match,		1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"If-Modified-Since\",	H_If_Modified_Since,	1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"If-None-Match\",		H_If_None_Match,	1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"If-Range\",		H_If_Range,		1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"If-Unmodified-Since\",	H_If_Unmodifed_Since,	1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Max-Forwards\",		H_Max_Forwards,		1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Proxy-Authorization\",	H_Proxy_Authorization,	1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Range\",			H_Range,		1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Referer\",		H_Referer,		1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"TE\",			H_TE,			1, 1, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"User-Agent\",		H_User_Agent,		1, 1, 0, 0, 0)\n", f);
+	fputs("\n", f);
+	fputs("HTTPH(\"Server\",			H_Server,		2, 0, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Content-Type\",		H_Content_Type,		2, 0, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Date\",			H_Date,			2, 0, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Last-Modified\",		H_Last_Modified,	2, 0, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Accept-Ranges\",		H_Accept_Ranges,	2, 0, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Content-Length\",		H_Content_Length,	2, 0, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Cache-Control\",		H_Cache_Control,	2, 0, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Vary\",			H_Vary,			2, 0, 0, 0, 0)\n", f);
+	fputs("HTTPH(\"Expires\",		H_Expires,		2, 0, 0, 0, 0)\n", f);
 	fputs("#undef HTTPH\n", f);
 	fputs("	const char		*uhdr[VCA_UNKNOWNHDR];\n", f);
 	fputs("	unsigned		nuhdr;\n", f);




More information about the varnish-commit mailing list