vtest	"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

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

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

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

process p1 {exec vinyllog -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

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

client c2 {
	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

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

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

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

vinyl 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 c3 {
	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

# Check default settings

vinyl v1 -cliok "param.reset h2_header_table_size"
vinyl v1 -cliok "param.reset h2_max_concurrent_streams"
vinyl v1 -cliok "param.reset h2_initial_window_size"
vinyl v1 -cliok "param.reset h2_max_frame_size"
vinyl v1 -cliok "param.reset h2_max_header_list_size"
vinyl v1 -cliok "param.reset http_req_size"

client c4 {
	txpri
	stream 0 {
		# check initial settings from vinyld
		txsettings
		rxsettings
		expect settings.ack == false
		expect settings.push == <undef>
		expect settings.hdrtbl == <undef>
		expect settings.maxstreams == 100
		expect settings.winsize == <undef>
		expect settings.framesize == <undef>
		expect settings.hdrsize ~ ^(12288|32768)$

		# check (some) values not set by vinyld
		expect stream.window == 65535

		txsettings -ack
		rxsettings
		expect settings.ack == true
	} -run
} -run
