r1968 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Thu Sep 20 10:46:25 CEST 2007


Author: phk
Date: 2007-09-20 10:46:25 +0200 (Thu, 20 Sep 2007)
New Revision: 1968

Modified:
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
Log:
After we moved pass to use the same code as fetch, we have run into
a unnecessary connection timeout wait when the returned object does
not have a body.

Rework the "does this response have a body" logic to be more in line
with the RFC.



Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2007-09-20 08:44:59 UTC (rev 1967)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2007-09-20 08:46:25 UTC (rev 1968)
@@ -260,7 +260,6 @@
 	struct worker *w;
 	char *b;
 	int cls;
-	int body = 1;		/* XXX */
 	struct http *hp, *hp2;
 	struct storage *st;
 	struct bereq *bereq;
@@ -338,17 +337,31 @@
 	http_CopyHome(sp->wrk, sp->fd, hp2);
 
 	CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC);
-	if (body) {
-		if (http_GetHdr(hp, H_Content_Length, &b))
-			cls = fetch_straight(sp, vc->fd, hp, b);
-		else if (http_HdrIs(hp, H_Transfer_Encoding, "chunked"))
-			cls = fetch_chunked(sp, vc->fd, hp);
-		else
-			cls = fetch_eof(sp, vc->fd, hp);
+
+	/* Determine if we have a body or not */
+	cls = 0;
+	if (http_GetHdr(hp, H_Content_Length, &b))
+		cls = fetch_straight(sp, vc->fd, hp, b);
+	else if (http_HdrIs(hp, H_Transfer_Encoding, "chunked"))
+		cls = fetch_chunked(sp, vc->fd, hp);
+	else if (http_GetHdr(hp, H_Transfer_Encoding, &b)) {
+		/* XXX: AUGH! */
+		VSL(SLT_Debug, vc->fd, "Invalid Transfer-Encoding");
+		VBE_ClosedFd(sp->wrk, vc);
+		return (-1);
+	} else if (strcmp(http_GetProto(hp), "HTTP/1.1")) {
+		switch (http_GetStatus(hp)) {
+			case 200:
+				cls = fetch_eof(sp, vc->fd, hp);
+				break;
+			default:
+				break;
+		}
+	}
+
+	if (cls > 0) 
 		http_PrintfHeader(sp->wrk, sp->fd, hp2,
 		    "Content-Length: %u", sp->obj->len);
-	} else
-		cls = 0;
 
 	CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC);
 	if (cls < 0) {




More information about the varnish-commit mailing list