r3470 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Thu Dec 18 12:30:03 CET 2008


Author: phk
Date: 2008-12-18 12:30:02 +0100 (Thu, 18 Dec 2008)
New Revision: 3470

Modified:
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_http.c
Log:
Change the logic that decides when we attempt EOF fetches from the
backend.

The new logic is:
	If (HEAD)	/* happens only on pass */
		do not fetch body.
	else if (Content-Length)
		fetch body according to length
	else if (chunked)
		fetch body as chunked
	else if (other transfer-encoding)
		fail
	else if (Connection: keep-alive)
		fetch no body, set Length = 0
	else if (Connection: close)
		fetch body until EOF
	else if (HTTP < 1.1)
		fetch body until EOF
	else
		fetch no body, set Length = 0

let me know if this breaks anything that should work.

Fixes #400



Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2008-12-18 10:58:17 UTC (rev 3469)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2008-12-18 11:30:02 UTC (rev 3470)
@@ -414,15 +414,31 @@
 		WSL(sp->wrk, SLT_Debug, vc->fd, "Invalid Transfer-Encoding");
 		VBE_ClosedFd(sp);
 		return (__LINE__);
+	} else if (http_HdrIs(hp, H_Connection, "keep-alive")) {
+		/*
+		 * If we have Connection: keep-alive, it cannot possibly be
+		 * EOF encoded, and since it is neither length nor chunked
+		 * it must be zero length.
+		 */
+		mklen = 1;
+	} else if (http_HdrIs(hp, H_Connection, "close")) {
+		/*
+		 * If we have connection closed, it is safe to read what
+		 * comes in any case.
+		 */
+		cls = fetch_eof(sp, htc);
+		mklen = 1;
+	} else if (hp->protover < 1.1) {
+		/*
+		 * With no Connection header, assume EOF
+		 */
+		cls = fetch_eof(sp, htc);
+		mklen = 1;
 	} else {
-		switch (http_GetStatus(hp)) {
-			case 200:
-				cls = fetch_eof(sp, htc);
-				mklen = 1;
-				break;
-			default:
-				break;
-		}
+		/*
+		 * Assume zero length
+		 */
+		mklen = 1;
 	}
 
 	if (cls < 0) {
@@ -451,7 +467,7 @@
 		http_PrintfHeader(sp->wrk, sp->fd, hp2,
 		    "Content-Length: %u", sp->obj->len);
 
-	if (http_GetHdr(hp, H_Connection, &b) && !strcasecmp(b, "close"))
+	if (http_HdrIs(hp, H_Connection, "close")) 
 		cls = 1;
 
 	if (cls)

Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2008-12-18 10:58:17 UTC (rev 3469)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2008-12-18 11:30:02 UTC (rev 3470)
@@ -251,7 +251,7 @@
 	unsigned u;
 
 	if (!http_GetHdr(hp, H_Connection, &p)) {
-		if (strcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.1"))
+		if (hp->protover < 1.1)
 			return ("not HTTP/1.1");
 		return (NULL);
 	}
@@ -442,6 +442,21 @@
 
 /*--------------------------------------------------------------------*/
 
+static void
+http_ProtoVer(struct http *hp)
+{
+
+	if (!strcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.0"))
+		hp->protover = 1.0;
+	else if (!strcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.1"))
+		hp->protover = 1.1;
+	else
+		hp->protover = 0.9;
+}
+
+
+/*--------------------------------------------------------------------*/
+
 int
 http_DissectRequest(struct sess *sp)
 {
@@ -463,13 +478,7 @@
 		WSPR(sp, SLT_HttpGarbage, htc->rxbuf);
 		return (i);
 	}
-
-	if (!strcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.0"))
-		hp->protover = 1.0;
-	else if (!strcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.1"))
-		hp->protover = 1.1;
-	else
-		hp->protover = 0.9;
+	http_ProtoVer(hp);
 	return (i);
 }
 
@@ -497,6 +506,7 @@
 		hp->status =
 		    strtoul(hp->hd[HTTP_HDR_STATUS].b, NULL /* XXX */, 10);
 	}
+	http_ProtoVer(hp);
 	if (hp->hd[HTTP_HDR_RESPONSE].b == NULL ||
 	    !Tlen(hp->hd[HTTP_HDR_RESPONSE])) {
 		/* Backend didn't send a response string, use the standard */



More information about the varnish-commit mailing list