vtest "H2 POST"

barrier b2 sock 2
barrier b3 sock 2

server s1 {
	rxreq
	expect req.http.content-length == 7
	expect req.http.transfer-encoding == <undef>
	txresp -noserver -hdr "Accept-ranges: bytes" -hdr "Content-Type: text/plain" -body response

	rxreq
	txresp -noserver -hdr "Accept-ranges: bytes"
} -start

vinyl v1 -vcl+backend {
	import vtc;
	sub vcl_recv {
		if (req.url == "/a") {
			vtc.barrier_sync("${b2_sock}");
			vtc.barrier_sync("${b3_sock}");
			return (fail);
		}
	}

	sub vcl_deliver {
		# make ReqAcct deterministic
		unset resp.http.via;
	}
} -cliok "param.set feature +http2" -start
vinyl v1 -cliok "param.set debug +syncvsl"

logexpect l1 -v v1 -g raw {
	expect	* 1001 ReqAcct	"80 7 87 76 8 84"
	expect	* 1000 ReqAcct	"45 8 53 63 34 97"
} -start

client c1 {
	stream 0 {
		txping
		rxping
	} -run
	stream 1 {
		txreq -req POST -hdr content-type text/plain -hdr content-length 7 -body request
		# First, HTTP checks
		rxresp
		expect resp.http.content-Type == "text/plain"

		# Then, payload checks
		expect resp.body == response
	} -run
} -run

client c2 {
	stream 0 {
		barrier b2 sync
		delay 1
		barrier b3 sync
	} -start
	stream 1 {
		txreq -url "/a" -req POST -nostrend
		txdata -datalen 100
		rxresp
		expect resp.status == 503
	} -run
	stream 3 {
		txreq -url "/b"
		rxresp
		expect resp.status == 200
	} -run
	stream 0 -wait
} -run

logexpect l1 -wait
