]> err.no Git - varnish/commitdiff
After we moved pass to use the same code as fetch, we have run into
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 20 Sep 2007 08:46:25 +0000 (08:46 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 20 Sep 2007 08:46:25 +0000 (08:46 +0000)
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

varnish-cache/bin/varnishd/cache_fetch.c

index 4a9f59ba2778c5691b724efddb16328658018e39..bbb2bcc354a359afeda329da7102a94b93567fce 100644 (file)
@@ -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) {