r3663 - branches/2.0/varnish-cache/bin/varnishd
tfheen at projects.linpro.no
tfheen at projects.linpro.no
Fri Feb 6 13:54:33 CET 2009
Author: tfheen
Date: 2009-02-06 13:54:33 +0100 (Fri, 06 Feb 2009)
New Revision: 3663
Modified:
branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c
branches/2.0/varnish-cache/bin/varnishd/cache_http.c
Log:
Merge r3470: 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: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-06 12:51:00 UTC (rev 3662)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-06 12:54:33 UTC (rev 3663)
@@ -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: branches/2.0/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-06 12:51:00 UTC (rev 3662)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-06 12:54:33 UTC (rev 3663)
@@ -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