vtest "VMOD vfp & vdp"

server s1 {
	rxreq
	txresp -body "Ponto Facto, Caesar Transit!"
	rxreq
	txresp -body "Ponto Facto, Caesar Transit!"
	accept
	rxreq
	txresp -body "Ponto Facto, Caesar Transit!"
} -start

vinyl v1 -vcl+backend {
	import debug;

	sub vcl_backend_response {
		set beresp.filters = "rot13";
	}
} -start

client c1 {
	txreq -hdr "Cookie: a"
	rxresp
	expect resp.body == "Cbagb Snpgb, Pnrfne Genafvg!"
} -run

vinyl v1 -vsl_catchup

vinyl v1 -vcl+backend {
	import debug;

	sub vcl_backend_response {
		set beresp.filters = "rot13 debug.slow rot13a";
	}
}

client c1 {
	txreq -hdr "Cookie: a"
	rxresp
	expect resp.status == 503
} -run


vinyl v1 -vcl+backend {
	import debug;

	sub vcl_backend_response {
		set beresp.filters = "rot13 rot14";
	}
}

client c1 {
	txreq -hdr "Cookie: a"
	rxresp
	expect resp.status == 503
} -run

server s1 -wait
server s1 {
	rxreq
	txresp -body "Ponto Facto, Caesar Transit!"
} -start

vinyl v1 -vcl+backend {
	import debug;

	sub vcl_deliver {
		if (req.http.Rot13) {
			set resp.filters = "debug.slow rot13 debug.pedantic";
		}
	}
}

client c1 -repeat 2 {
	txreq
	rxresp
	expect resp.body == "Ponto Facto, Caesar Transit!"
	txreq -hdr "Rot13: please"
	rxresp
	expect resp.body == "Cbagb Snpgb, Pnrfne Genafvg!"
} -run

vinyl v1 -vcl {
	import debug;
	backend none none;

	sub vcl_recv {
		return (synth(200));
	}
	sub vcl_synth {
		set resp.body = "Ponto Facto, Caesar Transit!";
		if (req.http.Rot13) {
			set resp.filters += "debug.slow rot13 debug.chunked debug.pedantic";
		}
		return (deliver);
	}
}

client c1 -repeat 2 {
	txreq
	rxresp
	expect resp.http.Content-Length == 28
	expect resp.body == "Ponto Facto, Caesar Transit!"
	txreq -hdr "Rot13: please"
	rxresp
	expect resp.http.Content-Length == <undef>
	expect resp.http.Transfer-Encoding == "chunked"
	expect resp.body == "Cbagb Snpgb, Pnrfne Genafvg!"
} -run
