vtest "Test request byte counters on pipe"

server s1 {
	rxreq
	expect req.url == "/"
	expect req.http.test == "yes"
	txresp -nodate -body "fdsa"
} -start

vinyl v1 -vcl+backend {
	sub vcl_recv {
		# make PipeAcct deterministic
		unset req.http.via;
		return (pipe);
	}

	sub vcl_pipe {
		set bereq.http.test = "yes";
		unset bereq.http.x-forwarded-for;
		unset bereq.http.X-Vinyl;
		unset bereq.http.connection;
	}
} -start

# req:
# POST / HTTP/1.1\r\n			17 bytes
# Host: foo\r\n				11 bytes
# Content-Length: 4\r\n			19 bytes
# User-Agent: c1\r\n			16 bytes
# \r\n					 2 bytes
# Total:				65 bytes

# bereq:
# POST / HTTP/1.1\r\n			17 bytes
# Content-Length: 4\r\n			19 bytes
# Host: foo\r\n				11 bytes
# User-Agent: c1\r\n			16 bytes
# test: yes\r\n				11 bytes
# \r\n					 2 bytes
# Total:				76 bytes

# reqbody
# asdf					 4 bytes

# resp:
# HTTP/1.1 200 OK\r\n			17 bytes
# Content-Length: 4\r\n			19 bytes
# Server: s1\r\n		 	12 bytes
# \r\n					 2 bytes
# fdsa					 4 bytes
# Total:				54 bytes

logexpect l1 -v v1 -g request {
	expect 0 1001	Begin		"^req .* rxreq"
	expect * =	PipeAcct	"^65 76 4 54$"
	expect 0 =	End
} -start

client c1 {
	txreq -req "POST" -url "/" -hdr "Content-Length: 4" -hdr "Host: foo"
	send "asdf"
	rxresp
	expect resp.status == 200
} -run

logexpect l1 -wait

vinyl v1 -expect s_pipe_hdrbytes == 65
vinyl v1 -expect s_pipe_in == 4
vinyl v1 -expect s_pipe_out == 54
