r1999 - in branches/1.1: . bin/varnishd

des at projects.linpro.no des at projects.linpro.no
Sun Sep 23 16:23:57 CEST 2007


Author: des
Date: 2007-09-23 16:23:56 +0200 (Sun, 23 Sep 2007)
New Revision: 1999

Modified:
   branches/1.1/
   branches/1.1/bin/varnishd/cache.h
   branches/1.1/bin/varnishd/cache_fetch.c
   branches/1.1/bin/varnishd/cache_http.c
Log:
Merged revisions 1967-1968,1970,1984,1986-1989,1992-1993,1995-1998 via svnmerge from 
svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache

........
  r1967 | phk | 2007-09-20 10:44:59 +0200 (Thu, 20 Sep 2007) | 2 lines
  
  Add a http_GetProto() function
........
  r1968 | phk | 2007-09-20 10:46:25 +0200 (Thu, 20 Sep 2007) | 8 lines
  
  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.
........
  r1970 | phk | 2007-09-20 12:44:18 +0200 (Thu, 20 Sep 2007) | 4 lines
  
  Fix a brain-o in my last commit.  "cls" is a flag for closing the fd,
  not for generating Content-Length: header.
........
  r1997 | phk | 2007-09-23 15:46:43 +0200 (Sun, 23 Sep 2007) | 6 lines
  
  Fix another cornercase that fell out as part of the pass->fetch rewrite:
  
  If we pass a HEAD request, we should not rewrite it to GET and not expect
  a body either.
........
  r1998 | des | 2007-09-23 16:19:42 +0200 (Sun, 23 Sep 2007) | 2 lines
  
  Reverse the logic in r1997 from !is_get to is_head.
........



Property changes on: branches/1.1
___________________________________________________________________
Name: svnmerge-integrated
   - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1798,1800-1808,1810-1815,1817,1819,1823,1830-1838,1846,1853-1855,1857-1859,1862,1865-1868,1871-1880,1883-1884,1886,1896,1898,1902-1905,1907,1909,1912-1916,1920-1928,1935-1939,1941-1949,1955,1957-1958,1984,1986-1989,1992-1994
   + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1798,1800-1808,1810-1815,1817,1819,1823,1830-1838,1846,1853-1855,1857-1859,1862,1865-1868,1871-1880,1883-1884,1886,1896,1898,1902-1905,1907,1909,1912-1916,1920-1928,1935-1939,1941-1949,1955,1957-1958,1967-1968,1970,1984,1986-1989,1992-1998

Modified: branches/1.1/bin/varnishd/cache.h
===================================================================
--- branches/1.1/bin/varnishd/cache.h	2007-09-23 14:19:42 UTC (rev 1998)
+++ branches/1.1/bin/varnishd/cache.h	2007-09-23 14:23:56 UTC (rev 1999)
@@ -427,6 +427,8 @@
 int http_GetHdr(struct http *hp, const char *hdr, char **ptr);
 int http_GetHdrField(struct http *hp, const char *hdr, const char *field, char **ptr);
 int http_GetStatus(struct http *hp);
+const char *http_GetReq(struct http *hp);
+const char *http_GetProto(struct http *hp);
 int http_HdrIs(struct http *hp, const char *hdr, const char *val);
 int http_GetTail(struct http *hp, unsigned len, char **b, char **e);
 int http_Read(struct http *hp, int fd, void *b, unsigned len);

Modified: branches/1.1/bin/varnishd/cache_fetch.c
===================================================================
--- branches/1.1/bin/varnishd/cache_fetch.c	2007-09-23 14:19:42 UTC (rev 1998)
+++ branches/1.1/bin/varnishd/cache_fetch.c	2007-09-23 14:23:56 UTC (rev 1999)
@@ -259,11 +259,10 @@
 	struct worker *w;
 	char *b;
 	int cls;
-	int body = 1;		/* XXX */
 	struct http *hp, *hp2;
 	struct storage *st;
 	struct bereq *bereq;
-	int len;
+	int len, mklen, is_head;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
@@ -272,6 +271,7 @@
 	w = sp->wrk;
 	bereq = sp->bereq;
 	hp = bereq->http;
+	is_head = (strcasecmp(http_GetReq(hp), "head") == 0);
 
 	sp->obj->xid = sp->xid;
 
@@ -282,7 +282,6 @@
 	http_Write(w, hp, 0);
 	if (WRK_Flush(w)) {
 		/* XXX: cleanup */
-		
 		return (1);
 	}
 
@@ -327,17 +326,37 @@
 	http_FilterFields(sp->wrk, sp->fd, hp2, hp, HTTPH_A_INS);
 	http_CopyHome(sp->wrk, sp->fd, hp2);
 
-	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;
+	mklen = 0;
+	if (is_head) {
+		/* nothing */
+	} else if (http_GetHdr(hp, H_Content_Length, &b)) {
+		cls = fetch_straight(sp, vc->fd, hp, b);
+		mklen = 1;
+	} else if (http_HdrIs(hp, H_Transfer_Encoding, "chunked")) {
+		cls = fetch_chunked(sp, vc->fd, hp);
+		mklen = 1;
+	} 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);
+				mklen = 1;
+				break;
+			default:
+				break;
+		}
+	}
+
+	if (mklen > 0)
 		http_PrintfHeader(sp->wrk, sp->fd, hp2,
 		    "Content-Length: %u", sp->obj->len);
-	} else
-		cls = 0;
 
 	if (cls < 0) {
 		while (!TAILQ_EMPTY(&sp->obj->store)) {

Modified: branches/1.1/bin/varnishd/cache_http.c
===================================================================
--- branches/1.1/bin/varnishd/cache_http.c	2007-09-23 14:19:42 UTC (rev 1998)
+++ branches/1.1/bin/varnishd/cache_http.c	2007-09-23 14:23:56 UTC (rev 1999)
@@ -381,6 +381,20 @@
 	    NULL /* XXX */, 10));
 }
 
+const char *
+http_GetProto(struct http *hp)
+{
+	AN(hp->hd[HTTP_HDR_PROTO].b);
+	return (hp->hd[HTTP_HDR_PROTO].b);
+}
+
+const char *
+http_GetReq(struct http *hp)
+{
+	AN(hp->hd[HTTP_HDR_REQ].b);
+	return (hp->hd[HTTP_HDR_REQ].b);
+}
+
 /*--------------------------------------------------------------------
  * Dissect the headers of the HTTP protocol message.
  * Detect conditionals (headers which start with '^[Ii][Ff]-')
@@ -792,7 +806,8 @@
         hp = bereq->http;
         hp->logtag = HTTP_Tx;
 
-	http_copyreq(hp, sp->http, how != HTTPH_R_PIPE);
+	http_copyreq(hp, sp->http,
+	    (how == HTTPH_R_PIPE) || (how == HTTPH_R_PASS));
 	http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how);
 	http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid);
 	http_PrintfHeader(sp->wrk, sp->fd, hp,




More information about the varnish-commit mailing list