]> err.no Git - varnish/commitdiff
Add http_ClrHeader() and cure an unintended bug-oid its use exposes:
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 31 Jul 2006 21:04:43 +0000 (21:04 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 31 Jul 2006 21:04:43 +0000 (21:04 +0000)
we checked if the request is a GET long after we should have.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@577 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_center.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_response.c

index 3872493932e6554055610fc01c71ea266a73a39b..ec20ad7b0874ca3ec69e3c9673be98577f9e9316 100644 (file)
@@ -244,6 +244,7 @@ struct sess {
 
        enum step               step;
        unsigned                handling;
+       unsigned char           wantbody;
 
        TAILQ_ENTRY(sess)       list;
 
@@ -322,6 +323,7 @@ void HSH_Init(void);
 
 /* cache_http.c */
 void HTTP_Init(void);
+void http_ClrHeader(struct http *to);
 void http_CopyHttp(struct http *to, struct http *fm);
 unsigned http_Write(struct worker *w, struct http *hp, int resp);
 void http_GetReq(int fd, struct http *to, struct http *fm);
index 93369c03aa31d8a5c13942fd7e3d6f7155f6dc79..6690afa4d86b1ad79eb6f1f242a03d58f0a7f2a3 100644 (file)
@@ -543,6 +543,7 @@ cnt_recv(struct sess *sp)
        switch(sp->handling) {
        case VCL_RET_LOOKUP:
                /* XXX: discard req body, if any */
+               sp->wantbody = !strcmp(sp->http->hd[HTTP_HDR_REQ].b, "GET");
                sp->step = STP_LOOKUP;
                return (0);
        case VCL_RET_PIPE:
index ead22c108e21986d9cad569aa539f6264ad22d12..b5964edb50daf23f2c66adcf54bb10a96f566fdd 100644 (file)
@@ -228,8 +228,7 @@ FetchBody(struct sess *sp)
         * The actual headers to reply with are built later on over in
         * cache_response.c
         */
-       sp->http->f = sp->http->v;
-       sp->http->nhd = HTTP_HDR_FIRST;
+       http_ClrHeader(sp->http);
        sp->http->objlog = 1;   /* log as SLT_ObjHeader */
        http_CopyResp(sp->fd, sp->http, vc->http);
        http_FilterHeader(sp->fd, sp->http, vc->http, HTTPH_A_INS);
@@ -247,7 +246,6 @@ FetchBody(struct sess *sp)
                cls = 0;
        sp->http->objlog = 0;
        http_CopyHttp(&sp->obj->http, sp->http);
-       sp->http->f = sp->http->v;
 
        if (http_GetHdr(vc->http, H_Connection, &b) && !strcasecmp(b, "close"))
                cls = 1;
index 8f319b414ff85cf930e2395f1273f834e99e2344..f2a1d69aa7d42f6f2bcefcbb0218cea00eedeef2 100644 (file)
@@ -628,10 +628,23 @@ http_FilterHeader(int fd, struct http *to, struct http *fm, unsigned how)
 
 /*--------------------------------------------------------------------*/
 
+void
+http_ClrHeader(struct http *to)
+{
+
+       CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
+       to->f = to->v;
+       to->nhd = HTTP_HDR_FIRST;
+       memset(to->hd, 0, sizeof to->hd);
+}
+
+/*--------------------------------------------------------------------*/
+
 void
 http_SetHeader(int fd, struct http *to, const char *hdr)
 {
 
+       CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
        to->hd[to->nhd].b = (void*)(uintptr_t)hdr;
        to->hd[to->nhd].e = strchr(hdr, '\0');
        assert(to->hd[to->nhd].e != NULL);
@@ -647,6 +660,7 @@ http_PrintfHeader(int fd, struct http *to, const char *fmt, ...)
        va_list ap;
        unsigned l, n;
 
+       CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
        va_start(ap, fmt);
        l = to->e - to->f;
        n = vsnprintf(to->f, l, fmt, ap);
index 62440fe0b4864e284be7e744d386dd990bd33e10..f92b1cb5945a291fe3f74bbc25b50c6fe0c6e757 100644 (file)
@@ -148,8 +148,7 @@ PassBody(struct sess *sp)
        vc = sp->vbc;
        assert(vc != NULL);
 
-       sp->http->f = sp->http->v;
-       sp->http->nhd = HTTP_HDR_FIRST;
+       http_ClrHeader(sp->http);
        http_CopyResp(sp->fd, sp->http, vc->http);
        http_FilterHeader(sp->fd, sp->http, vc->http, HTTPH_A_PASS);
        http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
index c9d049f0f86d4db534555d7ef114a6e5e8d5db5c..7b64b6f50eddb5af72dd6f6c09a09338a848a4f5 100644 (file)
@@ -79,14 +79,10 @@ static void
 res_do_304(struct sess *sp, char *p)
 {
 
-       VSL(SLT_Status, sp->fd, "%u", 304);
        VSL(SLT_Length, sp->fd, "%u", 0);
 
-       sp->http->f = sp->http->v;
-
+       http_ClrHeader(sp->http);
        http_SetResp(sp->fd, sp->http, "HTTP/1.1", "304", "Not Modified");
-
-       sp->http->nhd = HTTP_HDR_FIRST;
        http_SetHeader(sp->fd, sp->http, "Via: 1.1 varnish");
        http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
        http_PrintfHeader(sp->fd, sp->http, "Last-Modified: %s", p);
@@ -135,15 +131,14 @@ RES_WriteObj(struct sess *sp)
        if (sp->obj->response == 200 && sp->http->conds && res_do_conds(sp))
                return;
                
-       VSL(SLT_Status, sp->fd, "%u", sp->obj->response);
        VSL(SLT_Length, sp->fd, "%u", sp->obj->len);
 
-       sp->http->f = sp->http->v;
-       sp->http->nhd = HTTP_HDR_FIRST;
+       http_ClrHeader(sp->http);
        http_CopyResp(sp->fd, sp->http, &sp->obj->http);
        http_FilterHeader(sp->fd, sp->http, &sp->obj->http, HTTPH_A_DELIVER);
        if (sp->xid != sp->obj->xid)
-               http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u %u", sp->xid, sp->obj->xid);
+               http_PrintfHeader(sp->fd, sp->http,
+                   "X-Varnish: %u %u", sp->xid, sp->obj->xid);
        else
                http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
        http_PrintfHeader(sp->fd, sp->http, "Age: %u",
@@ -155,7 +150,7 @@ RES_WriteObj(struct sess *sp)
        sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
        
        /* XXX: conditional request handling */
-       if (!strcmp(sp->http->hd[HTTP_HDR_REQ].b, "GET")) {
+       if (sp->wantbody) {
                TAILQ_FOREACH(st, &sp->obj->store, list) {
                        assert(st->stevedore != NULL);
                        u += st->len;