From: phk Date: Thu, 20 Sep 2007 08:46:25 +0000 (+0000) Subject: After we moved pass to use the same code as fetch, we have run into X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5b1f39061d6d7334b4a059669a1ecd05a18a0ef;p=varnish 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. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1968 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 4a9f59ba..bbb2bcc3 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -260,7 +260,6 @@ Fetch(struct sess *sp) 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 @@ Fetch(struct sess *sp) 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) {