[master] dc2ef5e Ignore H2 upgrades if the feature is not enabled.

Poul-Henning Kamp phk at FreeBSD.org
Tue Sep 13 08:45:10 CEST 2016


commit dc2ef5e8584c6aa1a1eee32de8d17f6f3c412f4f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Sep 13 06:44:32 2016 +0000

    Ignore H2 upgrades if the feature is not enabled.
    
    Fixes: #2086

diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index 4c44102..66752be 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -416,21 +416,21 @@ HTTP1_Session(struct worker *wrk, struct req *req)
 				http1_setstate(sp, H1CLEANUP);
 				continue;
 			}
-			if (req->htc->body_status == BS_NONE && /* XXX */
-			    http_HdrIs(req->http, H_Upgrade, "h2c")) {
+			if (http_HdrIs(req->http, H_Upgrade, "h2c")) {
 				if (!FEATURE(FEATURE_HTTP2)) {
 					VSLb(req->vsl, SLT_Debug,
 					    "H2 upgrade attempt");
-					SES_Close(req->sp, req->doclose);
-					http1_setstate(sp, H1CLEANUP);
-					continue;
+				} else if (req->htc->body_status != BS_NONE) {
+					VSLb(req->vsl, SLT_Debug,
+					    "H2 upgrade attempt has body");
+				} else {
+					VSLb(req->vsl, SLT_Debug, "H2 Upgrade");
+					http1_setstate(sp, NULL);
+					req->err_code = 2;
+					SES_SetTransport(wrk, sp, req,
+					    &H2_transport);
+					return;
 				}
-				VSLb(req->vsl, SLT_Debug,
-				    "H2 Upgrade");
-				http1_setstate(sp, NULL);
-				req->err_code = 2;
-				SES_SetTransport(wrk, sp, req, &H2_transport);
-				return;
 			}
 			req->req_step = R_STP_RECV;
 			http1_setstate(sp, H1PROC);
diff --git a/bin/varnishtest/tests/t02001.vtc b/bin/varnishtest/tests/t02001.vtc
index af32f27..a7fa8b0 100644
--- a/bin/varnishtest/tests/t02001.vtc
+++ b/bin/varnishtest/tests/t02001.vtc
@@ -4,18 +4,39 @@ barrier b1 cond 2
 
 server s1 {
 	rxreq
+	expect req.url == /noupgrade
 	expect req.http.host == foo.bar
-	barrier b1 sync
 	txresp -status 400 -bodylen 10
 } -start
 
 varnish v1 -vcl+backend {} -start
 
-varnish v1 -cliok "param.set feature +http2"
+varnish v1 -cliok "param.set feature -http2"
 varnish v1 -cliok "param.set debug +syncvsl"
 
 client c1 {
-	send "GET / HTTP/1.1\r\n"
+	send "GET /noupgrade HTTP/1.1\r\n"
+	send "Host: foo.bar\r\n"
+	send "Upgrade: h2c\r\n"
+	send "HTTP2-Settings: AAMAAABkAAQAAP__\r\n"
+	send "\r\n"
+	rxresp
+	expect resp.status == 400
+	expect resp.bodylen == 10
+} -run
+
+server s1 {
+	rxreq
+	expect req.url == /upgrade
+	expect req.http.host == foo.bar
+	barrier b1 sync
+	txresp -status 401 -bodylen 11
+} -start
+
+varnish v1 -cliok "param.set feature +http2"
+
+client c1 {
+	send "GET /upgrade HTTP/1.1\r\n"
 	send "Host: foo.bar\r\n"
 	send "Upgrade: h2c\r\n"
 	send "HTTP2-Settings: AAMAAABkAAQAAP__\r\n"
@@ -35,7 +56,7 @@ client c1 {
 	barrier b1 sync
 	stream 1 {
 		rxresp
-		expect resp.status == 400
-		expect resp.bodylen == 10
+		expect resp.status == 401
+		expect resp.bodylen == 11
 	} -run
 } -run



More information about the varnish-commit mailing list