varnishtest "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

varnish 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

varnish v1 -cliok "param.set fetch_chunksize 4k"
varnish 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
varnish v1 -expect SM?.s0.c_req > 2

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

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

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