[master] 3c08479 Setting the default Host: header belongs in the backend code, not in the HTTP1 code.

Poul-Henning Kamp phk at FreeBSD.org
Wed Jun 24 22:45:12 CEST 2015


commit 3c08479d771b14aae887ff3a68d1b0d450fbb0aa
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jun 24 19:07:01 2015 +0000

    Setting the default Host: header belongs in the backend code, not in
    the HTTP1 code.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index effe64a..5616b10 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -205,6 +205,14 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk,
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC);
 
+	/*
+	 * Now that we know our backend, we can set a default Host:
+	 * 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) && bp->hosthdr != NULL)
+		http_PrintfHeader(bo->bereq, "Host: %s", bp->hosthdr);
+
 	do {
 		i = vbe_dir_getfd(wrk, bp, bo);
 		if (i < 0) {
@@ -215,7 +223,7 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk,
 		if (bo->htc->vbc->state != VBC_STATE_STOLEN)
 			extrachance = 0;
 
-		i = V1F_SendReq(wrk, bo, bp->hosthdr);
+		i = V1F_SendReq(wrk, bo);
 
 		if (bo->htc->vbc->state != VBC_STATE_USED)
 			VBT_Wait(wrk, bo->htc->vbc);
diff --git a/bin/varnishd/http1/cache_http1.h b/bin/varnishd/http1/cache_http1.h
index 8a80605..9e5a45a 100644
--- a/bin/varnishd/http1/cache_http1.h
+++ b/bin/varnishd/http1/cache_http1.h
@@ -28,7 +28,7 @@
  */
 
 /* cache_http1_fetch.c [V1F] */
-int V1F_SendReq(struct worker *, struct busyobj *, const char *def_host);
+int V1F_SendReq(struct worker *, struct busyobj *);
 int V1F_FetchRespHdr(struct busyobj *);
 void V1F_Setup_Fetch(struct vfp_ctx *vfc, struct http_conn *htc);
 
diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c
index 15d4168..2fe3c18 100644
--- a/bin/varnishd/http1/cache_http1_fetch.c
+++ b/bin/varnishd/http1/cache_http1_fetch.c
@@ -75,7 +75,7 @@ vbf_iter_req_body(struct req *req, void *priv, void *ptr, size_t l)
  */
 
 int
-V1F_SendReq(struct worker *wrk, struct busyobj *bo, const char *def_host)
+V1F_SendReq(struct worker *wrk, struct busyobj *bo)
 {
 	struct http *hp;
 	int j;
@@ -91,14 +91,6 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, const char *def_host)
 	htc = bo->htc;
 	hp = bo->bereq;
 
-	/*
-	 * Now that we know our backend, we can set a default Host:
-	 * 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) && def_host != NULL)
-		http_PrintfHeader(hp, "Host: %s", def_host);
-
 	if (bo->req != NULL &&
 	    bo->req->req_body_status == REQ_BODY_WITHOUT_LEN) {
 		http_PrintfHeader(hp, "Transfer-Encoding: chunked");



More information about the varnish-commit mailing list