From 29650b968d8dc01bf4c5d21a2356727b2297cdf9 Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 3 Jul 2007 21:50:31 +0000 Subject: [PATCH] Move the header-filtering another step backwards, so it comes before the VCL methods vcl_miss and vcl_pass. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1638 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 3 +- varnish-cache/bin/varnishd/cache_center.c | 46 ++++----------------- varnish-cache/bin/varnishd/cache_fetch.c | 2 +- varnish-cache/bin/varnishd/cache_http.c | 28 ++++++++++++- varnish-cache/bin/varnishd/cache_response.c | 3 +- 5 files changed, 39 insertions(+), 43 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index b15e84ec..238a31c7 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -411,7 +411,8 @@ void http_GetReq(struct http *to, struct http *fm); void http_CopyReq(struct http *to, struct http *fm); void http_CopyResp(struct http *to, struct http *fm); void http_SetResp(struct http *to, const char *proto, const char *status, const char *response); -void http_FilterHeader(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how); +void http_FilterFields(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how); +void http_FilterHeader(struct sess *sp, unsigned how); void http_PutProtocol(struct worker *w, int fd, struct http *to, const char *protocol); void http_PutStatus(struct worker *w, int fd, struct http *to, int status); void http_PutResponse(struct worker *w, int fd, struct http *to, const char *response); diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index d9b871cd..acf274ac 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -278,27 +278,9 @@ DOT errfetch [label="ERROR",shape=plaintext] static int cnt_fetch(struct sess *sp) { - struct bereq *bereq; - struct http *hp; - char *b; int i; - bereq = vbe_new_bereq(); - AN(bereq); - hp = bereq->http; - hp->logtag = HTTP_Tx; - - http_GetReq(hp, sp->http); - http_FilterHeader(sp->wrk, sp->fd, hp, sp->http, HTTPH_R_FETCH); - http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); - http_PrintfHeader(sp->wrk, sp->fd, hp, - "X-Forwarded-for: %s", sp->addr); - if (!http_GetHdr(hp, H_Host, &b)) { - http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s", - sp->backend->hostname); - } - sp->bereq = bereq; - + AN(sp->bereq); i = Fetch(sp); vbe_free_bereq(sp->bereq); sp->bereq = NULL; @@ -527,6 +509,7 @@ static int cnt_miss(struct sess *sp) { + http_FilterHeader(sp, HTTPH_R_FETCH); VCL_miss_method(sp); if (sp->handling == VCL_RET_ERROR) { sp->obj->cacheable = 0; @@ -542,6 +525,8 @@ cnt_miss(struct sess *sp) HSH_Deref(sp->obj); sp->obj = NULL; sp->step = STP_PASS; + vbe_free_bereq(sp->bereq); + sp->bereq = NULL; return (0); } if (sp->handling == VCL_RET_FETCH) { @@ -583,6 +568,8 @@ cnt_pass(struct sess *sp) AZ(sp->obj); + http_FilterHeader(sp, HTTPH_R_PASS); + VCL_pass_method(sp); if (sp->handling == VCL_RET_ERROR) { sp->step = STP_ERROR; @@ -624,34 +611,15 @@ DOT err_pipe [label="ERROR",shape=plaintext] static int cnt_pipe(struct sess *sp) { - struct bereq *bereq; - struct http *hp; - char *b; sp->wrk->acct.pipe++; - - bereq = vbe_new_bereq(); - XXXAN(bereq); - hp = bereq->http; - hp->logtag = HTTP_Tx; - - http_CopyReq(hp, sp->http); - http_FilterHeader(sp->wrk, sp->fd, hp, sp->http, HTTPH_R_PIPE); - http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); - http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Forwarded-for: %s", sp->addr); - - /* XXX: does this belong in VCL ? */ - if (!http_GetHdr(hp, H_Host, &b)) { - http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s", - sp->backend->hostname); - } + http_FilterHeader(sp, HTTPH_R_PIPE); VCL_pipe_method(sp); if (sp->handling == VCL_RET_ERROR) INCOMPL(); - sp->bereq = bereq; PipeSession(sp); sp->step = STP_DONE; return (0); diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 02485d3b..b3034f69 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -321,7 +321,7 @@ Fetch(struct sess *sp) hp2->logtag = HTTP_Obj; http_CopyResp(hp2, hp); - http_FilterHeader(sp->wrk, sp->fd, hp2, hp, HTTPH_A_INS); + http_FilterFields(sp->wrk, sp->fd, hp2, hp, HTTPH_A_INS); http_CopyHome(sp->wrk, sp->fd, hp2); if (body) { diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 7bface8c..a731b425 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -773,7 +773,7 @@ http_copyheader(struct worker *w, int fd, struct http *to, struct http *fm, unsi /*--------------------------------------------------------------------*/ void -http_FilterHeader(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how) +http_FilterFields(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how) { unsigned u; @@ -792,6 +792,32 @@ http_FilterHeader(struct worker *w, int fd, struct http *to, struct http *fm, un } } +/*--------------------------------------------------------------------*/ + +void +http_FilterHeader(struct sess *sp, unsigned how) +{ + struct bereq *bereq; + struct http *hp; + char *b; + + bereq = vbe_new_bereq(); + AN(bereq); + hp = bereq->http; + hp->logtag = HTTP_Tx; + + http_GetReq(hp, sp->http); + http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how); + http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); + http_PrintfHeader(sp->wrk, sp->fd, hp, + "X-Forwarded-for: %s", sp->addr); + if (!http_GetHdr(hp, H_Host, &b)) { + http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s", + sp->backend->hostname); + } + sp->bereq = bereq; +} + /*-------------------------------------------------------------------- * This function copies any header fields which reference foreign * storage into our own WS. diff --git a/varnish-cache/bin/varnishd/cache_response.c b/varnish-cache/bin/varnishd/cache_response.c index 934ba086..045c461b 100644 --- a/varnish-cache/bin/varnishd/cache_response.c +++ b/varnish-cache/bin/varnishd/cache_response.c @@ -130,7 +130,8 @@ RES_WriteObj(struct sess *sp) http_ClrHeader(sp->http); sp->http->logtag = HTTP_Tx; http_CopyResp(sp->http, &sp->obj->http); - http_FilterHeader(sp->wrk, sp->fd, sp->http, &sp->obj->http, HTTPH_A_DELIVER); + http_FilterFields(sp->wrk, sp->fd, sp->http, &sp->obj->http, + HTTPH_A_DELIVER); if (sp->xid != sp->obj->xid) http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u %u", sp->xid, sp->obj->xid); -- 2.39.5