void VBE_DropRef(struct backend *);
struct backend *VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb);
void VBE_UpdateHealth(const struct sess *sp, const struct vbe_conn *, int);
+void VBE_AddHostHeader(struct sess *sp);
+void VBE_SelectBackend(struct sess *sp);
/* cache_ban.c */
void AddBan(const char *, int hash);
static VTAILQ_HEAD(, backend) backends =
VTAILQ_HEAD_INITIALIZER(backends);
+/*--------------------------------------------------------------------
+ * Create default Host: header for backend request
+ */
+void
+VBE_AddHostHeader(struct sess *sp)
+{
+
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC);
+ CHECK_OBJ_NOTNULL(sp->bereq->http, HTTP_MAGIC);
+ CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC);
+ http_PrintfHeader(sp->wrk, sp->fd, sp->bereq->http,
+ "Host: %s", sp->backend->vrt->hostname);
+}
+
/*--------------------------------------------------------------------
* Attempt to connect to a given addrinfo entry.
*
/*--------------------------------------------------------------------*/
-struct vbe_conn *
-VBE_GetFd(struct sess *sp)
+void
+VBE_SelectBackend(struct sess *sp)
{
struct backend *bp;
- struct vbe_conn *vc;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
bp = sp->director->choose(sp);
CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC);
sp->backend = bp;
+}
+
+/*--------------------------------------------------------------------*/
+
+struct vbe_conn *
+VBE_GetFd(struct sess *sp)
+{
+ struct backend *bp;
+ struct vbe_conn *vc;
+
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ bp = sp->backend;
/* first look for vbe_conn's we can recycle */
while (1) {
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);
if (sp->handling == VCL_RET_ERROR) {
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
AZ(sp->obj);
+ VBE_SelectBackend(sp);
http_FilterHeader(sp, HTTPH_R_PASS);
VCL_pass_method(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);
http_PrintfHeader(sp->wrk, sp->fd, hp,
"X-Forwarded-for: %s", sp->addr);
- /* XXX: This really ought to go into the default VCL */
- if (!http_GetHdr(hp, H_Host, &b)) {
-#if 0
- http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s",
- sp->backend->method->gethostname(sp->backend));
-#endif
- INCOMPL();
- }
sp->bereq = bereq;
+
+ /* XXX: This possibly ought to go into the default VCL */
+ if (!http_GetHdr(hp, H_Host, &b))
+ VBE_AddHostHeader(sp);
}
/*--------------------------------------------------------------------