[master] bb75c9c Don't add another Connection: header if we already have one, but do insist on it being "close" if we need that.

Poul-Henning Kamp phk at FreeBSD.org
Mon Nov 3 11:55:21 CET 2014


commit bb75c9cdda5f389adae15b68c79d2023d79ed873
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Nov 3 10:54:31 2014 +0000

    Don't add another Connection: header if we already have one,
    but do insist on it being "close" if we need that.
    
    Test case by daghf
    
    Fixes #1613

diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index bc24ff3..c0eaeca 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -142,8 +142,13 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
 
 	VSLb(req->vsl, SLT_Debug, "RES_MODE %x", req->res_mode);
 
-	http_SetHeader(req->resp,
-	    req->doclose ? "Connection: close" : "Connection: keep-alive");
+	if (req->doclose) {
+		if (!http_HdrIs(req->resp, H_Connection, "close")) {
+			http_Unset(req->resp, H_Connection);
+			http_SetHeader(req->resp, "Connection: close");
+		}
+	} else if (!http_GetHdr(req->resp, H_Connection, NULL))
+		http_SetHeader(req->resp, "Connection: keep-alive");
 
 	VDP_push(req, v1d_bytes, NULL, 1);
 
diff --git a/bin/varnishtest/tests/r01613.vtc b/bin/varnishtest/tests/r01613.vtc
new file mode 100644
index 0000000..62c7213
--- /dev/null
+++ b/bin/varnishtest/tests/r01613.vtc
@@ -0,0 +1,32 @@
+varnishtest "Extra Connection header erroneously inserted."
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v2 -vcl+backend {
+	sub vcl_deliver {
+		set resp.http.Connection = "close";
+	}
+} -start
+
+varnish v1 -vcl {
+	import ${vmod_std};
+
+	backend b {
+		.host = "${v2_addr}";
+		.port = "${v2_port}";
+	}
+
+	sub vcl_backend_response {
+		std.collect(beresp.http.Connection);
+		set beresp.http.foo = beresp.http.Connection;
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.http.foo == "close"
+} -run



More information about the varnish-commit mailing list