[master] fd186d9 Fix conditional requests in H2.

Poul-Henning Kamp phk at FreeBSD.org
Mon Mar 13 08:48:05 CET 2017


commit fd186d9718f2651c13f8e8c278e4ed2c4e61510a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Mar 13 07:45:57 2017 +0000

    Fix conditional requests in H2.
    
    Fail vtc if -hdr doesn't have two args in H2 context.

diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c
index 0add0f9..d1070b3 100644
--- a/bin/varnishd/http2/cache_http2_proto.c
+++ b/bin/varnishd/http2/cache_http2_proto.c
@@ -436,6 +436,7 @@ h2_do_req(struct worker *wrk, void *priv)
 	CAST_OBJ_NOTNULL(req, priv, REQ_MAGIC);
 	CAST_OBJ_NOTNULL(r2, req->transport_priv, H2_REQ_MAGIC);
 	THR_SetRequest(req);
+	req->http->conds = 1;
 	if (CNT_Request(wrk, req) != REQ_FSM_DISEMBARK) {
 		VSL(SLT_Debug, 0, "H2REQ CNT done");
 		r2->state = H2_S_CLOSED;
diff --git a/bin/varnishtest/tests/t02010.vtc b/bin/varnishtest/tests/t02010.vtc
new file mode 100644
index 0000000..b6f24c9
--- /dev/null
+++ b/bin/varnishtest/tests/t02010.vtc
@@ -0,0 +1,80 @@
+varnishtest "Test H2 Client IMS"
+
+server s1 {
+	rxreq
+	expect req.url == "/foo"
+	txresp -hdr "Last-Modified: Thu, 26 Jun 2008 12:00:01 GMT" \
+	    -hdr {ETag: "foo"} \
+	    -body "11111\n"
+	rxreq
+	expect req.url == "/bar"
+	txresp -hdr "Last-Modified: Thu, 26 Jun 2008 12:00:01 GMT" \
+	    -hdr {ETag: "bar"}
+} -start
+
+varnish v1 -vcl+backend { } -start
+varnish v1 -cliok "param.set feature +http2"
+
+client c1 {
+	stream 1 {
+		txreq -url "/foo"
+		rxresp
+		expect resp.status == 200
+		expect resp.http.etag == {"foo"}
+		expect resp.http.content-length == "6"
+		expect resp.bodylen == 6
+	} -run
+	delay .1
+	stream 3 {
+		txreq -url "/foo" \
+		    -hdr "if-modified-since" "Thu, 26 Jun 2008 12:00:00 GMT"
+		rxresp
+		expect resp.status == 200
+		expect resp.http.content-length == "6"
+		expect resp.http.etag == {"foo"}
+		expect resp.bodylen == 6
+	} -run
+	delay .1
+	stream 5 {
+		txreq -url "/foo" \
+		    -hdr "if-modified-since" "Thu, 26 Jun 2008 12:00:01 GMT"
+		rxresp -no_obj
+		expect resp.status == 304
+		expect resp.http.etag == {"foo"}
+		expect resp.http.content-length == "<undef>"
+		expect resp.bodylen == 0
+	} -run
+	delay .1
+	stream 7 {
+		txreq -url "/foo" \
+		    -hdr "if-modified-since" "Thu, 26 Jun 2008 12:00:02 GMT"
+		rxresp -no_obj
+		expect resp.status == 304
+		expect resp.http.etag == {"foo"}
+		expect resp.http.content-length == "<undef>"
+		expect resp.bodylen == 0
+	} -run
+	delay .1
+	stream 9 {
+		txreq -url "/bar"
+		rxresp
+		expect resp.status == 200
+		expect resp.http.etag == {"bar"}
+		expect resp.http.content-length == "0"
+		expect resp.bodylen == 0
+	} -run
+	delay .1
+	stream 11 {
+		txreq -url "/bar" \
+		    -hdr "if-modified-since" "Thu, 26 Jun 2008 12:00:01 GMT"
+		rxresp -no_obj
+		expect resp.status == 304
+		expect resp.http.etag == {"bar"}
+		expect resp.http.content-length == <undef>
+		expect resp.bodylen == 0
+	} -run
+}
+
+client c1 -run
+
+# client c1 -run
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index 420a4db..b472d81 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -1452,6 +1452,8 @@ cmd_tx11obj(CMD_ARGS)
 			scheme_done = 1;
 		}
 		else if (AV_IS("-hdr")) {
+			if (av[2] == NULL)
+				vtc_fatal(vl, "-hdr takes two arguments in http2");
 			ENC(hdr, av[1], av[2]);
 			av += 2;
 		}



More information about the varnish-commit mailing list