r2464 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Fri Feb 15 09:54:20 CET 2008
Author: phk
Date: 2008-02-15 09:54:20 +0100 (Fri, 15 Feb 2008)
New Revision: 2464
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_backend.c
trunk/varnish-cache/bin/varnishd/cache_center.c
trunk/varnish-cache/bin/varnishd/cache_http.c
Log:
Determine our backend (using the director) before we filter the req
into the bereq, in order to be able to assign a default Host: header
if there is none.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2008-02-15 08:33:41 UTC (rev 2463)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2008-02-15 08:54:20 UTC (rev 2464)
@@ -415,6 +415,8 @@
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);
Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-02-15 08:33:41 UTC (rev 2463)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-02-15 08:54:20 UTC (rev 2464)
@@ -123,6 +123,21 @@
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.
*
* Must be called with locked backend, but will release the backend
@@ -406,18 +421,29 @@
/*--------------------------------------------------------------------*/
-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) {
LOCK(&bp->mtx);
Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c 2008-02-15 08:33:41 UTC (rev 2463)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c 2008-02-15 08:54:20 UTC (rev 2464)
@@ -617,6 +617,7 @@
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) {
@@ -680,6 +681,7 @@
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
AZ(sp->obj);
+ VBE_SelectBackend(sp);
http_FilterHeader(sp, HTTPH_R_PASS);
VCL_pass_method(sp);
@@ -729,6 +731,7 @@
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);
Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c 2008-02-15 08:33:41 UTC (rev 2463)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c 2008-02-15 08:54:20 UTC (rev 2464)
@@ -649,15 +649,11 @@
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);
}
/*--------------------------------------------------------------------
More information about the varnish-commit
mailing list