varnishtest "Include gzip'ed and ungzip'ed (ESI) objects in a gzip'ed ESI object"

server s1 {
	rxreq
	expect req.http.accept-encoding == gzip
	txresp -gzipbody {
		<html>					1
		Before includes				2
		<esi:include src="/foo"/>		3
		Between includes			4
		<esi:include src="/bar"/>		5
		Between includes			6
		<esi:include src="/fooz"/>		7
		Between includes			8
		<esi:include src="/barz"/>		9
		After includes				10
	}

	rxreq
	expect req.url == "/foo"
	txresp -body {<h1>/////<h2>}

	rxreq
	expect req.url == "/bar"
	txresp -body {*****}

	rxreq
	expect req.http.accept-encoding == gzip
	expect req.url == "/fooz"
	txresp -gzipbody {<h1>-----<h2>}

	rxreq
	expect req.http.accept-encoding == gzip
	expect req.url == "/barz"
	txresp -gzipbody {#####}
} -start

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

varnish v1 -cliok "param.set http_gzip_support true"
varnish v1 -cliok "param.set debug +esi_chop"
varnish v1 -cliok "param.set feature +esi_disable_xml_check"

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

client c1 {
	txreq -hdr "Accept-Encoding: gzip"
	rxresp
	expect resp.http.content-encoding == gzip
	gunzip
	expect resp.status == 200
	expect resp.bodylen == 192
}

client c1 -run
varnish v1 -expect esi_errors == 0
