From f8287c3601caec4abd32e25498d1f839951ae8fb Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 26 Jun 2006 19:23:24 +0000 Subject: [PATCH] Implement HTTP/1.0 style fetching. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@240 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_fetch.c | 61 ++++++++++++++++++++---- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index e100d25a..e00139dc 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -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 + +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; -- 2.39.5