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

phk at projects.linpro.no phk at projects.linpro.no
Tue Jul 11 09:30:53 CEST 2006


Author: phk
Date: 2006-07-11 09:30:53 +0200 (Tue, 11 Jul 2006)
New Revision: 420

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_http.c
   trunk/varnish-cache/bin/varnishd/cache_pass.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/include/stat_field.h
Log:
Split http_Dissect() into http_DissectRequest() and http_DissectResponse()



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-07-11 06:30:38 UTC (rev 419)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-07-11 07:30:53 UTC (rev 420)
@@ -230,7 +230,8 @@
 int http_GetTail(struct http *hp, unsigned len, char **b, char **e);
 int http_GetURL(struct http *hp, char **b);
 void http_RecvHead(struct http *hp, int fd, struct event_base *eb, http_callback_f *func, void *arg);
-int http_Dissect(struct http *sp, int fd, int rr);
+int http_DissectRequest(struct http *sp, int fd);
+int http_DissectResponse(struct http *sp, int fd);
 enum http_build {
 	Build_Pipe,
 	Build_Pass,

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-07-11 06:30:38 UTC (rev 419)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-07-11 07:30:53 UTC (rev 420)
@@ -261,7 +261,7 @@
 	http_RecvHead(hp, vc->fd, w->eb, NULL, NULL);
 	event_base_loop(w->eb, 0);
 	time(&sp->t_resp);
-	assert(http_Dissect(hp, vc->fd, 2) == 0);
+	assert(http_DissectResponse(hp, vc->fd) == 0);
 
 	body = RFC2616_cache_policy(sp, hp);
 

Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-11 06:30:38 UTC (rev 419)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-11 07:30:53 UTC (rev 420)
@@ -157,91 +157,11 @@
 
 /*--------------------------------------------------------------------*/
 
-int
-http_Dissect(struct http *hp, int fd, int rr)
+static int
+http_dissect_hdrs(struct http *hp, int fd, char *p)
 {
-	char *p, *q, *r;
+	char *q, *r;
 
-	assert(hp->t != NULL);
-	assert(hp->s < hp->t);
-	assert(hp->t <= hp->v);
-	for (p = hp->s ; isspace(*p); p++)
-		continue;
-	if (rr == 1) {
-		/* First, the request type (GET/HEAD etc) */
-		hp->req = p;
-		for (; isalpha(*p); p++)
-			;
-		VSLR(SLT_Request, fd, hp->req, p);
-		*p++ = '\0';
-
-		/* Next find the URI */
-		while (isspace(*p) && *p != '\n')
-			p++;
-		if (*p == '\n') {
-			VSLR(SLT_Debug, fd, hp->s, hp->v);
-			return (400);
-		}
-		hp->url = p;
-		while (!isspace(*p))
-			p++;
-		VSLR(SLT_URL, fd, hp->url, p);
-		if (*p == '\n') {
-			VSLR(SLT_Debug, fd, hp->s, hp->v);
-			return (400);
-		}
-		*p++ = '\0';
-
-		/* Finally, look for protocol */
-		while (isspace(*p) && *p != '\n')
-			p++;
-		if (*p == '\n') {
-			VSLR(SLT_Debug, fd, hp->s, hp->v);
-			return (400);
-		}
-		hp->proto = p;
-		while (!isspace(*p))
-			p++;
-		VSLR(SLT_Protocol, fd, hp->proto, p);
-		if (*p != '\n')
-			*p++ = '\0';
-		while (isspace(*p) && *p != '\n')
-			p++;
-		if (*p != '\n') {
-			VSLR(SLT_Debug, fd, hp->s, hp->v);
-			return (400);
-		}
-		*p++ = '\0';
-	} else {
-		/* First, protocol */
-		hp->proto = p;
-		while (!isspace(*p))
-			p++;
-		VSLR(SLT_Protocol, fd, hp->proto, p);
-		*p++ = '\0';
-
-		/* Next find the status */
-		while (isspace(*p))
-			p++;
-		hp->status = p;
-		while (!isspace(*p))
-			p++;
-		VSLR(SLT_Status, fd, hp->status, p);
-		*p++ = '\0';
-
-		/* Next find the response */
-		while (isspace(*p))
-			p++;
-		hp->response = p;
-		while (*p != '\n')
-			p++;
-		for (q = p; q > hp->response && isspace(q[-1]); q--)
-			continue;
-		*q = '\0';
-		VSLR(SLT_Response, fd, hp->response, q);
-		p++;
-	}
-
 	if (*p == '\r')
 		p++;
 
@@ -262,6 +182,7 @@
 			hp->hdr[hp->nhdr++] = p;
 			VSLR(SLT_Header, fd, p, q);
 		} else {
+			VSL_stats->losthdr++;
 			VSLR(SLT_LostHeader, fd, p, q);
 		}
 	}
@@ -274,6 +195,111 @@
 
 /*--------------------------------------------------------------------*/
 
+int
+http_DissectRequest(struct http *hp, int fd)
+{
+	char *p;
+
+	assert(hp->t != NULL);
+	assert(hp->s < hp->t);
+	assert(hp->t <= hp->v);
+	for (p = hp->s ; isspace(*p); p++)
+		continue;
+
+	/* First, the request type (GET/HEAD etc) */
+	hp->req = p;
+	for (; isalpha(*p); p++)
+		;
+	VSLR(SLT_Request, fd, hp->req, p);
+	*p++ = '\0';
+
+	/* Next find the URI */
+	while (isspace(*p) && *p != '\n')
+		p++;
+	if (*p == '\n') {
+		VSLR(SLT_Debug, fd, hp->s, hp->v);
+		return (400);
+	}
+	hp->url = p;
+	while (!isspace(*p))
+		p++;
+	VSLR(SLT_URL, fd, hp->url, p);
+	if (*p == '\n') {
+		VSLR(SLT_Debug, fd, hp->s, hp->v);
+		return (400);
+	}
+	*p++ = '\0';
+
+	/* Finally, look for protocol */
+	while (isspace(*p) && *p != '\n')
+		p++;
+	if (*p == '\n') {
+		VSLR(SLT_Debug, fd, hp->s, hp->v);
+		return (400);
+	}
+	hp->proto = p;
+	while (!isspace(*p))
+		p++;
+	VSLR(SLT_Protocol, fd, hp->proto, p);
+	if (*p != '\n')
+		*p++ = '\0';
+	while (isspace(*p) && *p != '\n')
+		p++;
+	if (*p != '\n') {
+		VSLR(SLT_Debug, fd, hp->s, hp->v);
+		return (400);
+	}
+	*p++ = '\0';
+
+	return (http_dissect_hdrs(hp, fd, p));
+}
+
+/*--------------------------------------------------------------------*/
+
+int
+http_DissectResponse(struct http *hp, int fd)
+{
+	char *p, *q;
+
+	assert(hp->t != NULL);
+	assert(hp->s < hp->t);
+	assert(hp->t <= hp->v);
+	for (p = hp->s ; isspace(*p); p++)
+		continue;
+
+	/* First, protocol */
+	hp->proto = p;
+	while (!isspace(*p))
+		p++;
+	VSLR(SLT_Protocol, fd, hp->proto, p);
+	*p++ = '\0';
+
+	/* Next find the status */
+	while (isspace(*p))
+		p++;
+	hp->status = p;
+	while (!isspace(*p))
+		p++;
+	VSLR(SLT_Status, fd, hp->status, p);
+	*p++ = '\0';
+
+	/* Next find the response */
+	while (isspace(*p))
+		p++;
+	hp->response = p;
+	while (*p != '\n')
+		p++;
+	for (q = p; q > hp->response && isspace(q[-1]); q--)
+		continue;
+	*q = '\0';
+	VSLR(SLT_Response, fd, hp->response, q);
+	p++;
+
+	return (http_dissect_hdrs(hp, fd, p));
+}
+
+/*--------------------------------------------------------------------*/
+
 static int
 http_header_complete(struct http *hp)
 {

Modified: trunk/varnish-cache/bin/varnishd/cache_pass.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pass.c	2006-07-11 06:30:38 UTC (rev 419)
+++ trunk/varnish-cache/bin/varnishd/cache_pass.c	2006-07-11 07:30:53 UTC (rev 420)
@@ -170,7 +170,7 @@
 	hp = vc->http;
 	http_RecvHead(hp, vc->fd, w->eb, NULL, NULL);
 	event_base_loop(w->eb, 0);
-	http_Dissect(hp, vc->fd, 2);
+	http_DissectResponse(hp, vc->fd);
 
 	http_BuildSbuf(sp->fd, Build_Reply, w->sb, hp);
 	vca_write(sp, sbuf_data(w->sb), sbuf_len(w->sb));

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-07-11 06:30:38 UTC (rev 419)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-07-11 07:30:53 UTC (rev 420)
@@ -68,7 +68,7 @@
 	sp->vcl = GetVCL();
 	AZ(pthread_mutex_unlock(&sessmtx));
 
-	done = http_Dissect(sp->http, sp->fd, 1);
+	done = http_DissectRequest(sp->http, sp->fd);
 	if (done != 0) {
 		RES_Error(w, sp, done, NULL);
 		goto out;

Modified: trunk/varnish-cache/include/stat_field.h
===================================================================
--- trunk/varnish-cache/include/stat_field.h	2006-07-11 06:30:38 UTC (rev 419)
+++ trunk/varnish-cache/include/stat_field.h	2006-07-11 07:30:53 UTC (rev 420)
@@ -21,3 +21,5 @@
 MAC_STAT(n_wrk_failed,		uint64_t, "u", "N worker threads not created");
 MAC_STAT(n_wrk_short,		uint64_t, "u", "N worker threads shortages");
 MAC_STAT(n_wrk_busy,		uint64_t, "u", "N busy worker threads");
+
+MAC_STAT(losthdr,		uint64_t, "u", "HTTP header overflows");




More information about the varnish-commit mailing list