]> err.no Git - varnish/commitdiff
Fix HEAD requests:
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 4 Jul 2006 20:00:27 +0000 (20:00 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 4 Jul 2006 20:00:27 +0000 (20:00 +0000)
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

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/bin/varnishd/cache_fetch.c
varnish-cache/bin/varnishd/cache_http.c
varnish-cache/bin/varnishd/cache_pass.c
varnish-cache/bin/varnishd/cache_pipe.c
varnish-cache/bin/varnishd/cache_pool.c
varnish-cache/bin/varnishd/cache_shmlog.c

index 502455e9bd482ee8be52e042c81a1b4535080636..8c56c55478d0584b15385c01900b9bcefe4b4e40 100644 (file)
@@ -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;
index 004ee5fcfe67041b68a76618cbeb9e6e9371611d..03f290f91338c1b43a390e7a5924fad18f7d1652 100644 (file)
@@ -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);
 }
 
index 844ad545e7f73acbbf310d8d73ec182da87b58ab..e4442608a754748855afda279252319a9b545efa 100644 (file)
@@ -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);
index 906d4d92ec5690b6275694708fde804dd8ebd938..a1ee542497b4e4fd54df14015787400ca9e27b09 100644 (file)
@@ -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);
        }
index c3749ef49ec614f2fd894adb73e1851f2d0aa921..a7df2b345b54fc9a5bc17402a2c250bb3ed84904 100644 (file)
@@ -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));
 
index 779e1379e1e9e4713504b603557a1d351c6e502c..29fb92780bd725f3404674f0773895d8d8717820 100644 (file)
@@ -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);
index a58218399a56428fa68127e72c5d416acd3594e1..ae8118be76a6ebb30a10fef3453f08b693d69ccc 100644 (file)
@@ -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));
index b4005d1c6e25a0f003e8ebefce3bafd3b1caa864..854219c351ce7aed2ab944bb78bf787ba87ed046 100644 (file)
@@ -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",