vtest "Test Backend IMS"

server s1 {
	rxreq
	txresp -hdr "Last-Modified: Wed, 11 Sep 2013 13:36:55 GMT" -body "Geoff Rules"
	rxreq
	expect req.http.if-modified-since == "Wed, 11 Sep 2013 13:36:55 GMT"
	txresp -status 304
	rxreq
	expect req.http.if-modified-since == "Wed, 11 Sep 2013 13:36:55 GMT"
	txresp -status 304
} -start

vinyl v1 -cliok "param.set vsl_mask +ExpKill"
vinyl v1 -vcl+backend {
	sub vcl_backend_response {
		set beresp.ttl = 2s;
		set beresp.grace = 20s;
		set beresp.keep = 1m;
		set beresp.http.was-304 = beresp.was_304;
	}
} -start

logexpect l1 -v v1 -g raw -q ExpKill {
	expect * 0 ExpKill "VBF_Superseded x=1002 n=1005"
	expect * 0 ExpKill "EXP_Removed x=1002"
	expect * 0 ExpKill "VBF_Superseded x=1005 n=1010"
	expect * 0 ExpKill "EXP_Removed x=1005"
} -start

client c1 {
	txreq
	rxresp
	expect resp.status == 200
	expect resp.body == "Geoff Rules"
	expect resp.http.was-304 == "false"
} -run

delay 3

client c1 {
	txreq
	rxresp
	expect resp.status == 200
	expect resp.body == "Geoff Rules"
	expect resp.http.was-304 == "false"
} -run

delay 1

client c1 {
	txreq
	rxresp
	expect resp.status == 200
	expect resp.body == "Geoff Rules"
	expect resp.http.was-304 == "true"
} -run

delay 2

client c1 {
	txreq
	rxresp
	expect resp.status == 200
	expect resp.body == "Geoff Rules"
	expect resp.http.was-304 == "true"
} -run

logexpect l1 -wait

vinyl v1 -expect MAIN.n_superseded == 2
