Commit 617608c9 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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: http://www.varnish-cache.org/svn/trunk@3118 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 6f3154cc
...@@ -412,7 +412,7 @@ extern int vca_pipes[2]; ...@@ -412,7 +412,7 @@ extern int vca_pipes[2];
/* cache_backend.c */ /* 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_ClosedFd(struct worker *w, struct vbe_conn *vc);
void VBE_RecycleFd(struct worker *w, struct vbe_conn *vc); void VBE_RecycleFd(struct worker *w, struct vbe_conn *vc);
struct bereq * VBE_new_bereq(void); struct bereq * VBE_new_bereq(void);
......
...@@ -267,13 +267,16 @@ bes_conn_try(const struct sess *sp, struct backend *bp) ...@@ -267,13 +267,16 @@ bes_conn_try(const struct sess *sp, struct backend *bp)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
struct vbe_conn * struct vbe_conn *
VBE_GetFd(const struct sess *sp) VBE_GetFd(struct sess *sp)
{ {
struct backend *bp; struct backend *bp;
struct vbe_conn *vc; struct vbe_conn *vc;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
VBE_SelectBackend(sp);
bp = sp->backend; bp = sp->backend;
CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC);
/* first look for vbe_conn's we can recycle */ /* first look for vbe_conn's we can recycle */
while (1) { while (1) {
......
...@@ -686,7 +686,6 @@ cnt_miss(struct sess *sp) ...@@ -686,7 +686,6 @@ cnt_miss(struct sess *sp)
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
VBE_SelectBackend(sp);
http_FilterHeader(sp, HTTPH_R_FETCH); http_FilterHeader(sp, HTTPH_R_FETCH);
VCL_miss_method(sp); VCL_miss_method(sp);
switch(sp->handling) { switch(sp->handling) {
...@@ -761,7 +760,6 @@ cnt_pass(struct sess *sp) ...@@ -761,7 +760,6 @@ cnt_pass(struct sess *sp)
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
AZ(sp->obj); AZ(sp->obj);
VBE_SelectBackend(sp);
http_FilterHeader(sp, HTTPH_R_PASS); http_FilterHeader(sp, HTTPH_R_PASS);
VCL_pass_method(sp); VCL_pass_method(sp);
...@@ -813,7 +811,6 @@ cnt_pipe(struct sess *sp) ...@@ -813,7 +811,6 @@ cnt_pipe(struct sess *sp)
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
sp->wrk->acct.pipe++; sp->wrk->acct.pipe++;
VBE_SelectBackend(sp);
http_FilterHeader(sp, HTTPH_R_PIPE); http_FilterHeader(sp, HTTPH_R_PIPE);
VCL_pipe_method(sp); VCL_pipe_method(sp);
......
...@@ -335,6 +335,15 @@ Fetch(struct sess *sp) ...@@ -335,6 +335,15 @@ Fetch(struct sess *sp)
vc = VBE_GetFd(sp); vc = VBE_GetFd(sp);
if (vc == NULL) if (vc == NULL)
return (__LINE__); 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 */ TCP_blocking(vc->fd); /* XXX: we should timeout instead */
WRK_Reset(w, &vc->fd); WRK_Reset(w, &vc->fd);
http_Write(w, hp, 0); /* XXX: stats ? */ http_Write(w, hp, 0); /* XXX: stats ? */
......
...@@ -642,7 +642,6 @@ http_FilterHeader(struct sess *sp, unsigned how) ...@@ -642,7 +642,6 @@ http_FilterHeader(struct sess *sp, unsigned how)
{ {
struct bereq *bereq; struct bereq *bereq;
struct http *hp; struct http *hp;
char *b;
bereq = VBE_new_bereq(); bereq = VBE_new_bereq();
AN(bereq); AN(bereq);
...@@ -656,10 +655,6 @@ http_FilterHeader(struct sess *sp, unsigned how) ...@@ -656,10 +655,6 @@ http_FilterHeader(struct sess *sp, unsigned how)
"X-Forwarded-For: %s", sp->addr); "X-Forwarded-For: %s", sp->addr);
sp->bereq = bereq; sp->bereq = bereq;
/* XXX: This possibly ought to go into the default VCL */
if (!http_GetHdr(hp, H_Host, &b))
VBE_AddHostHeader(sp);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment