vtest "test basic gunzip for client"

server s1 {
	rxreq
	expect req.http.accept-encoding == "gzip"
	expect req.url == "/foo"
	txresp -proto HTTP/1.0 -nolen -gziplen 4100
	accept
	rxreq
	expect req.url == "/bar"
	txresp -body {<H1><esi:include src="/foo"/></H1>}
} -start

vinyl v1 \
	-arg "-sdefault,2m" \
	-arg "-p feature=+esi_disable_xml_check" \
	-cliok "param.set http_gzip_support true" \
	-cliok "param.set gzip_memlevel 1" \
	-vcl+backend {

	import debug;

	sub vcl_backend_response {
		set beresp.do_esi = true;
	}

	sub vcl_deliver {
		set resp.filters += " debug.pedantic";
	}
} -start

vinyl v1 -cliok "param.set fetch_chunksize 4k"
vinyl v1 -cliok "param.set vsl_mask +VfpAcct"

client c1 {
	txreq -url /foo -hdr "Accept-Encoding: gzip"
	rxresp
	gunzip
	expect resp.http.content-encoding == "gzip"
	expect resp.bodylen == 4100
} -run

# If this fails, the multiple storage allocations did not happen
vinyl v1 -expect SM?.s0.c_req > 2

client c1 {
	# See vinyl can gunzip it.
	txreq -url /foo -hdr "Accept-Encoding: null"
	rxresp
	expect resp.http.content-encoding == <undef>
	expect resp.bodylen == 4100
	delay .1

	# See vinyl can gunzip it, inside ESI
	txreq -url /bar -hdr "Accept-Encoding: null"
	rxresp
	expect resp.http.content-encoding == <undef>
	expect resp.bodylen == 4109
} -run

vinyl v1 -expect n_gzip == 1
vinyl v1 -expect n_gunzip == 3
vinyl v1 -expect n_test_gunzip == 0
