varnishtest "ESI include"


server s1 {
	rxreq
	txresp -body {
		<html>
		Before include
		<esi:include src="/body" sr="foo"/>
		After include
		</html>
	}
	rxreq
	expect req.url == "/body1"
	txresp -body {
		Included file
	}
} -start

varnish v1 -vcl+backend {
	sub vcl_recv {
		if (req.esi_level > 0) {
			set req.url = req.url + req.esi_level;
		}
	}
	sub vcl_backend_response {
		if (bereq.url == "/") {
			set beresp.do_esi = true;
		}
	}
} -start

logexpect l1 -v v1 -g request {
	expect 0 1001   Begin   "^req .* rxreq"
	# ReqAcct body counts include chunked overhead
	expect * =	ReqAcct	"^29 0 29 187 104 291$"
	expect 0 =      End
} -start

logexpect l2 -v v1 -g request {
	expect * 1002   Begin   "^bereq "
	expect * =      End
} -start

logexpect l3 -v v1 -g request {
	expect * 1003   Begin   "^req .* esi"
	expect * =	ReqAcct	"^0 0 0 0 18 18$"
	expect 0 =      End
} -start

logexpect l4 -v v1 -g request {
	expect * 1004   Begin   "^bereq "
	expect * =      End
} -start

logexpect l5 -v v1 -g request {
	expect * 1005   Begin   "^req .* rxreq"
	# ReqAcct body counts include chunked overhead
	# Header bytes is 5 larger than in l1 due to two item X-Varnish hdr
	expect * =	ReqAcct	"^29 0 29 192 104 296$"
	expect 0 =      End
} -start

client c1 {
	txreq -hdr "Host: foo"
	rxresp
	expect resp.bodylen == 75
	expect resp.status == 200

	delay .1
	# test that there is no difference on miss/hit
	txreq -hdr "Host: foo"
	rxresp
	expect resp.bodylen == 75
	expect resp.status == 200
}

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

logexpect l1 -wait
logexpect l2 -wait
logexpect l3 -wait
logexpect l4 -wait
logexpect l5 -wait
