varnishtest "Ticket #873"

barrier b1 cond 2
barrier b2 cond 2
barrier b3 cond 2
barrier b4 cond 2

server s1 {
	rxreq
	txresp -nolen -hdr "Transfer-encoding: chunked"
	chunked "<1>------------------------<1>\n"
	barrier b1 sync
	chunked "<2>------------------------<2>\n"
	barrier b2 sync
	chunked "<3>------------------------<3>\n"
	barrier b3 sync
	chunked "<4>------------------------<4>\n"
	barrier b4 sync
	chunkedlen 0
} -start

varnish v1 -vcl+backend {
	sub vcl_backend_response {
		set beresp.do_stream = true;
	}
} -start

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

client c1 {
	txreq  -hdr "foo: /foo"
	rxresp -no_obj

	rxchunk
	expect resp.chunklen == 31
	barrier b1 sync

	rxchunk
	expect resp.chunklen == 31
	barrier b2 sync

	rxchunk
	expect resp.chunklen == 31
	barrier b3 sync

	rxchunk
	expect resp.chunklen == 31
	barrier b4 sync

	rxchunk
	expect resp.chunklen == 0
	expect resp.bodylen == 124
} -run
