varnishtest	"Direct H2 start"

server s1 {
	rxreq
	expect req.http.host == foo.bar
	txresp \
		-hdr "H234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789I: foo" \
		-hdr "Foo: H234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789I" \
		-bodylen 10
	rxreq
	txresp
	rxreq
	txresp
} -start

varnish v1 -vcl+backend {
	sub vcl_recv {
		return (pipe);
	}
} -start

varnish v1 -cliok "param.set debug +syncvsl"

varnish v1 -cliok "param.set vsl_mask +H2RxHdr,+H2RxBody,+H2TxHdr,+H2TxBody"

process p1 {exec varnishlog -n ${v1_name} -g raw -w ${tmpdir}/vlog -A} -start

shell {while ! test -s ${tmpdir}/vlog ; do sleep 1 ; done}

client c1 {
	txpri
	expect_close
} -run

varnish v1 -cliok "param.set feature +http2"
varnish v1 -cliok "param.reset h2_initial_window_size"

client c1 {
	stream 1 {
		txprio -weight 10 -stream 0
	} -run
	stream 3 {
		txprio -weight 10 -stream 0
	} -run
	stream 5 {
		txprio -weight 10 -stream 2
	} -run
	stream 7 {
		txreq -dep 3 -hdr :authority foo.bar -pad cotton
		rxresp
		expect resp.status == 200
		delay 1
		txrst -err 0x1111
	} -start
	stream 0 {
		txping -data "_-__-_-_"
		rxping
		expect ping.ack == "true"
		expect ping.data == "_-__-_-_"
	} -run
	stream 7 -wait
} -run

varnish v1 -expect MEMPOOL.req0.live == 0
varnish v1 -expect MEMPOOL.req1.live == 0
varnish v1 -expect MEMPOOL.sess0.live == 0
varnish v1 -expect MEMPOOL.sess1.live == 0

process p1 -stop
# shell {cat ${tmpdir}/vlog}
# SETTINGS with default initial window size
shell -match {1001 H2TxHdr        c \[000006040000000000\]} {
	cat ${tmpdir}/vlog
}

# While we're here, test sess.xid over H2 as well

varnish v1 -syntax 4.1 -vcl+backend {
	sub vcl_backend_response {
		set beresp.http.B-Sess-XID = sess.xid;
	}

	sub vcl_deliver {
		set resp.http.C-Sess-XID = sess.xid;
		set resp.http.xport = req.transport;
	}
}

client c1 {
	stream 7 {
		txreq -url "/uncached"
		rxresp
		expect resp.status == 200
		expect resp.http.C-Sess-XID ~ "^[0-9]+$"
		expect resp.http.B-Sess-XID ~ "^[0-9]+$"
		expect resp.http.C-Sess-XID == resp.http.B-Sess-XID
		expect resp.http.xport == HTTP/2
	} -run
	stream 9 {
		txreq -url "/still_not_cached"
		rxresp
		expect resp.status == 200
		expect resp.http.C-Sess-XID ~ "^[0-9]+$"
		expect resp.http.B-Sess-XID ~ "^[0-9]+$"
		expect resp.http.C-Sess-XID == resp.http.B-Sess-XID
	} -run
} -run
