vtest "test caching of req.body"

server s1 {
	rxreq
	expect req.bodylen == 3
	txresp -hdr "Connection: close" -hdr "Foo: BAR" -body "1234"

	expect_close
	accept

	rxreq
	expect req.bodylen == 3
	txresp -hdr "Foo: Foo" -body "56"
} -start

vinyl v1 -vcl+backend {
	import std;

	sub vcl_recv {
		set req.http.stored = std.cache_req_body(1KB);
		return (pass);
	}

	sub vcl_deliver {
		if (resp.http.foo == "BAR") {
			return (restart);
		}
		set resp.http.stored = req.http.stored;
	}

} -start

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

client c1 {
	txreq -req "POST" -body "FOO"
	rxresp
	expect resp.http.Foo == "Foo"
	expect resp.bodylen == 2
	expect resp.http.stored == true
} -run

# check log for the aborted POST
logexpect l1 -v v1 {
	expect * 1006	Begin
	expect * =	FetchError	"^straight insufficient bytes"
} -start

client c2 {
	txreq -req POST -hdr "Content-Length: 52"
} -run

logexpect l1 -wait

delay .1

vinyl v1 -expect MGT.child_died == 0

# no req body
server s1 {
	rxreq
	txresp
} -start

client c4 {
	txreq
	rxresp
	expect resp.status == 200
	expect resp.http.stored == true
} -run

# req body overflow
client c5 {
	txreq -req POST -hdr "Content-Length: 1025"
	rxresp
	expect resp.status == 400
} -run
