]> err.no Git - varnish/commitdiff
Implement HTTP/1.0 style fetching.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 26 Jun 2006 19:23:24 +0000 (19:23 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 26 Jun 2006 19:23:24 +0000 (19:23 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@240 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_fetch.c

index e100d25a371b4cfed37e2ac2990a02ec75f40ae3..e00139dcfbfe4dee294ead326d68d208321ced69 100644 (file)
@@ -188,12 +188,59 @@ fetch_chunked(struct worker *w, struct sess *sp, int fd, struct http *hp)
        http_BuildSbuf(2, w->sb, hp);
 
        vca_write_obj(sp, w->sb);
+       return (0);
+}
 
-#if 0
-       hash->deref(sp->obj);
-#endif
 
-       return (0);
+/*--------------------------------------------------------------------*/
+
+#include <errno.h>
+
+static int
+fetch_eof(struct worker *w, struct sess *sp, int fd, struct http *hp)
+{
+       int i;
+       char *b, *e;
+       unsigned char *p;
+       struct storage *st;
+       unsigned v;
+
+       i = fcntl(fd, F_GETFL);         /* XXX ? */
+       i &= ~O_NONBLOCK;
+       i = fcntl(fd, F_SETFL, i);
+
+       p = NULL;
+       v = 0;
+       while (1) {
+               if (v == 0) {
+                       st = stevedore->alloc(stevedore, CHUNK_PREALLOC);
+                       TAILQ_INSERT_TAIL(&sp->obj->store, st, list);
+                       p = st->ptr + st->len;
+                       v = st->space - st->len;
+               }
+               if (http_GetTail(hp, v, &b, &e)) {
+                       memcpy(p, b, e - b);
+                       p += e - b;
+                       v -= e - b;
+                       st->len += e - b;
+                       *p = '\0';
+               }
+               i = read(fd, p, v);
+               assert(i >= 0);
+               if (i == 0)
+                    break;
+               p += i;
+               v -= i;
+               st->len += i;
+       }
+
+       if (st != NULL && stevedore->trim != NULL)
+               stevedore->trim(st, st->len);
+
+       http_BuildSbuf(2, w->sb, hp);
+
+       vca_write_obj(sp, w->sb);
+       return (1);
 }
 
 /*--------------------------------------------------------------------*/
@@ -258,10 +305,8 @@ FetchSession(struct worker *w, struct sess *sp)
                cls = fetch_straight(w, sp, fd, hp, b);
        else if (http_HdrIs(hp, "Transfer-Encoding", "chunked"))
                cls = fetch_chunked(w, sp, fd, hp);
-       else {
-               VSL(SLT_Debug, fd, "No transfer");
-               cls = 0;
-       }
+       else 
+               cls = fetch_eof(w, sp, fd, hp);
 
        if (http_GetHdr(hp, "Connection", &b) && !strcasecmp(b, "close"))
                cls = 1;