From b1d70b8341cb26766d533f01264361d3b4ca0fc3 Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 21 Aug 2008 08:37:37 +0000 Subject: [PATCH] Move selection of backend and creation of default Host: header until we actually need to get a filedescriptor to the backend. This also makes it evident for vcl_pass{}, vcl_pipe{} and vcl_miss{} if the client sent a Host: header or not. Previously these functions saw the default Host: header. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3118 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 2 +- varnish-cache/bin/varnishd/cache_backend.c | 5 ++++- varnish-cache/bin/varnishd/cache_center.c | 3 --- varnish-cache/bin/varnishd/cache_fetch.c | 9 +++++++++ varnish-cache/bin/varnishd/cache_http.c | 5 ----- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 28d8ef62..0560ae68 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -412,7 +412,7 @@ extern int vca_pipes[2]; /* cache_backend.c */ -struct vbe_conn *VBE_GetFd(const struct sess *sp); +struct vbe_conn *VBE_GetFd(struct sess *sp); void VBE_ClosedFd(struct worker *w, struct vbe_conn *vc); void VBE_RecycleFd(struct worker *w, struct vbe_conn *vc); struct bereq * VBE_new_bereq(void); diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index 277c173d..23532ea4 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -267,13 +267,16 @@ bes_conn_try(const struct sess *sp, struct backend *bp) /*--------------------------------------------------------------------*/ struct vbe_conn * -VBE_GetFd(const struct sess *sp) +VBE_GetFd(struct sess *sp) { struct backend *bp; struct vbe_conn *vc; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + + VBE_SelectBackend(sp); bp = sp->backend; + CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); /* first look for vbe_conn's we can recycle */ while (1) { diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index 2b1a1633..193fdd8a 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -686,7 +686,6 @@ cnt_miss(struct sess *sp) CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); - VBE_SelectBackend(sp); http_FilterHeader(sp, HTTPH_R_FETCH); VCL_miss_method(sp); switch(sp->handling) { @@ -761,7 +760,6 @@ cnt_pass(struct sess *sp) CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); AZ(sp->obj); - VBE_SelectBackend(sp); http_FilterHeader(sp, HTTPH_R_PASS); VCL_pass_method(sp); @@ -813,7 +811,6 @@ cnt_pipe(struct sess *sp) CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); sp->wrk->acct.pipe++; - VBE_SelectBackend(sp); http_FilterHeader(sp, HTTPH_R_PIPE); VCL_pipe_method(sp); diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index b5e11682..681d894c 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -335,6 +335,15 @@ Fetch(struct sess *sp) vc = VBE_GetFd(sp); if (vc == NULL) return (__LINE__); + + /* + * Now that we know our backend, we can set a default Host: + * header if one is necessary. + * XXX: This possibly ought to go into the default VCL + */ + if (!http_GetHdr(hp, H_Host, &b)) + VBE_AddHostHeader(sp); + TCP_blocking(vc->fd); /* XXX: we should timeout instead */ WRK_Reset(w, &vc->fd); http_Write(w, hp, 0); /* XXX: stats ? */ diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index eff99611..a49d9fa2 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -642,7 +642,6 @@ http_FilterHeader(struct sess *sp, unsigned how) { struct bereq *bereq; struct http *hp; - char *b; bereq = VBE_new_bereq(); AN(bereq); @@ -656,10 +655,6 @@ http_FilterHeader(struct sess *sp, unsigned how) "X-Forwarded-For: %s", sp->addr); sp->bereq = bereq; - - /* XXX: This possibly ought to go into the default VCL */ - if (!http_GetHdr(hp, H_Host, &b)) - VBE_AddHostHeader(sp); } /*-------------------------------------------------------------------- -- 2.39.5