From: phk Date: Tue, 4 Jul 2006 20:00:27 +0000 (+0000) Subject: Fix HEAD requests: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dadffe64affc5600aa0eee289d19bf12e62ab384;p=varnish Fix HEAD requests: Make modes to http_BuildSbuf descriptive enums. Send GET to backend also for HEAD requests. Don't return body for HEAD requests. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@303 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 502455e9..8c56c554 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -178,7 +178,13 @@ int http_GetTail(struct http *hp, unsigned len, char **b, char **e); int http_GetURL(struct http *hp, char **b); void http_RecvHead(struct http *hp, int fd, struct event_base *eb, http_callback_f *func, void *arg); void http_Dissect(struct http *sp, int fd, int rr); -void http_BuildSbuf(int fd, int resp, struct sbuf *sb, struct http *hp); +enum http_build { + Build_Pipe, + Build_Pass, + Build_Fetch, + Build_Reply, +}; +void http_BuildSbuf(int fd, enum http_build mode, struct sbuf *sb, struct http *hp); /* cache_main.c */ extern pthread_mutex_t sessmtx; diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index 004ee5fc..03f290f9 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -89,18 +89,22 @@ vca_write_obj(struct sess *sp, char *b, unsigned l) { struct storage *st; unsigned u = 0; + char *r; if (l == 0) l = strlen(b); vca_write(sp, b, l); - TAILQ_FOREACH(st, &sp->obj->store, list) { - u += st->len; - if (st->stevedore->send != NULL) - st->stevedore->send(st, sp); - else - vca_write(sp, st->ptr, st->len); + assert(http_GetReq(sp->http, &r)); + if (!strcmp(r, "GET")) { + TAILQ_FOREACH(st, &sp->obj->store, list) { + u += st->len; + if (st->stevedore->send != NULL) + st->stevedore->send(st, sp); + else + vca_write(sp, st->ptr, st->len); + } + assert(u == sp->obj->len); } - assert(u == sp->obj->len); vca_flush(sp); } diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 844ad545..e4442608 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -249,7 +249,7 @@ FetchSession(struct worker *w, struct sess *sp) VSL(SLT_Backend, sp->fd, "%d %s", fd, sp->backend->vcl_name); hp = http_New(); - http_BuildSbuf(fd, 1, w->sb, sp->http); + http_BuildSbuf(fd, Build_Fetch, w->sb, sp->http); i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb)); assert(i == sbuf_len(w->sb)); time(&sp->t_req); @@ -272,7 +272,7 @@ FetchSession(struct worker *w, struct sess *sp) if (sp->obj->cacheable) EXP_Insert(sp->obj); - http_BuildSbuf(sp->fd, 3, w->sb, hp); + http_BuildSbuf(sp->fd, Build_Reply, w->sb, hp); if (body) { if (http_GetHdr(hp, "Content-Length", &b)) cls = fetch_straight(w, sp, fd, hp, b); diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 906d4d92..a1ee5424 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -415,39 +415,52 @@ http_supress(const char *hdr, int flag) /*--------------------------------------------------------------------*/ void -http_BuildSbuf(int fd, int resp, struct sbuf *sb, struct http *hp) +http_BuildSbuf(int fd, enum http_build mode, struct sbuf *sb, struct http *hp) { - unsigned u; + unsigned u, sup; sbuf_clear(sb); assert(sb != NULL); - if (resp == 2 || resp == 3) { + switch (mode) { + case Build_Reply: sbuf_cat(sb, hp->proto); sbuf_cat(sb, " "); sbuf_cat(sb, hp->status); sbuf_cat(sb, " "); sbuf_cat(sb, hp->response); - } else if (resp == 1) { + sup = 2; + break; + case Build_Pipe: + case Build_Pass: sbuf_cat(sb, hp->req); sbuf_cat(sb, " "); sbuf_cat(sb, hp->url); sbuf_cat(sb, " "); sbuf_cat(sb, hp->proto); - } else { - printf("resp = %d\n", resp); - assert(resp == 1 || resp == 2); + sup = 2; + break; + case Build_Fetch: + sbuf_cat(sb, "GET "); + sbuf_cat(sb, hp->url); + sbuf_cat(sb, " "); + sbuf_cat(sb, hp->proto); + sup = 1; + break; + default: + printf("mode = %d\n", mode); + assert(mode == 1 || mode == 2); } sbuf_cat(sb, "\r\n"); for (u = 0; u < hp->nhdr; u++) { - if (http_supress(hp->hdr[u], resp)) + if (http_supress(hp->hdr[u], sup)) continue; if (1) VSL(SLT_BldHdr, fd, "%s", hp->hdr[u]); sbuf_cat(sb, hp->hdr[u]); sbuf_cat(sb, "\r\n"); } - if (resp != 3) { + if (mode != Build_Reply) { sbuf_cat(sb, "\r\n"); sbuf_finish(sb); } diff --git a/varnish-cache/bin/varnishd/cache_pass.c b/varnish-cache/bin/varnishd/cache_pass.c index c3749ef4..a7df2b34 100644 --- a/varnish-cache/bin/varnishd/cache_pass.c +++ b/varnish-cache/bin/varnishd/cache_pass.c @@ -160,7 +160,7 @@ PassSession(struct worker *w, struct sess *sp) fd = VBE_GetFd(sp->backend, &fd_token, sp->xid); assert(fd != -1); - http_BuildSbuf(fd, 1, w->sb, sp->http); + http_BuildSbuf(fd, Build_Pass, w->sb, sp->http); i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb)); assert(i == sbuf_len(w->sb)); diff --git a/varnish-cache/bin/varnishd/cache_pipe.c b/varnish-cache/bin/varnishd/cache_pipe.c index 779e1379..29fb9278 100644 --- a/varnish-cache/bin/varnishd/cache_pipe.c +++ b/varnish-cache/bin/varnishd/cache_pipe.c @@ -51,7 +51,7 @@ PipeSession(struct worker *w, struct sess *sp) fd = VBE_GetFd(sp->backend, &fd_token, sp->xid); assert(fd != -1); - http_BuildSbuf(fd, 0, w->sb, sp->http); /* XXX: 0 ?? */ + http_BuildSbuf(fd, Build_Pipe, w->sb, sp->http); /* XXX: 0 ?? */ i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb)); assert(i == sbuf_len(w->sb)); assert(__LINE__ == 0); diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index a5821839..ae8118be 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -160,6 +160,7 @@ CacheInitPool(void) AZ(pthread_cond_init(&shdcnd, NULL)); + VSL(SLT_Debug, 0, "Starting %u worker threads", heritage.wthread_min); for (i = 0; i < heritage.wthread_min; i++) { AZ(pthread_create(&tp, NULL, CacheWorker, NULL)); AZ(pthread_detach(tp)); diff --git a/varnish-cache/bin/varnishd/cache_shmlog.c b/varnish-cache/bin/varnishd/cache_shmlog.c index b4005d1c..854219c3 100644 --- a/varnish-cache/bin/varnishd/cache_shmlog.c +++ b/varnish-cache/bin/varnishd/cache_shmlog.c @@ -151,7 +151,6 @@ VSL_MgtInit(const char *fn, unsigned size) struct shmloghead slh; int i; - unlink(fn); heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0600); if (heritage.vsl_fd < 0) { fprintf(stderr, "Could not open %s: %s\n",