[master] 155f11a Adding the default Host: header is a matter between the backend and V1F, it has nothing to do with the VDI layer.

Poul-Henning Kamp phk at FreeBSD.org
Wed Jan 7 14:18:04 CET 2015


commit 155f11a4ae462d2d866d0500d9b477d459277a9a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jan 7 13:17:26 2015 +0000

    Adding the default Host: header is a matter between the backend
    and V1F, it has nothing to do with the VDI layer.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 2e7fa47..7016fd7 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -717,7 +717,7 @@ void VBO_waitstate(struct busyobj *bo, enum busyobj_state_e want);
 
 
 /* cache_http1_fetch.c [V1F] */
-int V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo);
+int V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host);
 void V1F_Setup_Fetch(struct vfp_ctx *vfc, struct http_conn *htc);
 
 /* cache_http1_fsm.c [HTTP1] */
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 64139fb..70991f0 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -62,19 +62,6 @@ struct vbe_dir {
 	const struct vrt_backend *vrt;
 };
 
-/*--------------------------------------------------------------------
- * Create default Host: header for backend request
- */
-void
-VDI_AddHostHeader(struct http *hp, const struct vbc *vbc)
-{
-
-	CHECK_OBJ_NOTNULL(vbc, VBC_MAGIC);
-	CHECK_OBJ_NOTNULL(vbc->vdis, VDI_SIMPLE_MAGIC);
-	http_PrintfHeader(hp,
-	    "Host: %s", vbc->vdis->vrt->hosthdr);
-}
-
 /*--------------------------------------------------------------------*/
 
 /* Private interface from backend_cfg.c */
@@ -425,10 +412,12 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk,
     struct busyobj *bo)
 {
 	int i;
+	struct vbe_dir *vs;
 
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+	CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
 
 	i = vbe_dir_getfd(d, bo);
 	if (i < 0) {
@@ -437,7 +426,7 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk,
 	}
 	AN(bo->htc);
 
-	i = V1F_fetch_hdr(wrk, bo);
+	i = V1F_fetch_hdr(wrk, bo, vs->vrt->hosthdr);
 	/*
 	 * If we recycle a backend connection, there is a finite chance
 	 * that the backend closed it before we get a request to it.
@@ -455,7 +444,7 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk,
 			return (-1);
 		}
 		AN(bo->htc);
-		i = V1F_fetch_hdr(wrk, bo);
+		i = V1F_fetch_hdr(wrk, bo, vs->vrt->hosthdr);
 	}
 	if (i != 0) {
 		vbe_dir_finish(d, wrk, bo);
diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index 199fe3f..3fc4983 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -37,7 +37,6 @@
 
 #include "cache.h"
 
-// #include "cache_backend.h"
 #include "cache_director.h"
 
 /* Resolve director --------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_director.h b/bin/varnishd/cache/cache_director.h
index 3980356..3bdcb40 100644
--- a/bin/varnishd/cache/cache_director.h
+++ b/bin/varnishd/cache/cache_director.h
@@ -74,6 +74,5 @@ int VDI_GetBody(struct worker *wrk, struct busyobj *bo);
 void VDI_Finish(struct worker *wrk, struct busyobj *bo);
 int VDI_GetHttp1Fd(struct worker *wrk, struct busyobj *);
 int VDI_Healthy(const struct director *, const struct busyobj *);
-void VDI_AddHostHeader(struct http *to, const struct vbc *vbc);
 void VBE_Init(void);
 
diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c
index ac5448c..bb40205 100644
--- a/bin/varnishd/http1/cache_http1_fetch.c
+++ b/bin/varnishd/http1/cache_http1_fetch.c
@@ -74,7 +74,7 @@ vbf_iter_req_body(struct req *req, void *priv, void *ptr, size_t l)
  */
 
 int
-V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
+V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host)
 {
 	struct vbc *vc;
 	struct http *hp;
@@ -101,8 +101,8 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
 	 * header if one is necessary.  This cannot be done in the VCL
 	 * because the backend may be chosen by a director.
 	 */
-	if (!http_GetHdr(bo->bereq, H_Host, NULL))
-		VDI_AddHostHeader(bo->bereq, vc);
+	if (!http_GetHdr(bo->bereq, H_Host, NULL) && def_host != NULL)
+		http_PrintfHeader(hp, "Host: %s", def_host);
 
 	if (bo->req != NULL &&
 	    bo->req->req_body_status == REQ_BODY_WITHOUT_LEN) {



More information about the varnish-commit mailing list