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

varnish 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

varnish v1 -vsl_catchup

varnish v1 -vcl+backend {
	import debug;

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

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


varnish 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

varnish v1 -vcl+backend {
	import debug;

	sub vcl_deliver {
		if (req.http.Rot13) {
			set resp.filters = "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

varnish 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 += "rot13 debug.pedantic";
		}
		return (deliver);
	}
}

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
