varnishtest "VCL/VRT: url/request/proto/reason/status"

varnish v1 -errvcl "Variable is read only" {
	backend proforma None;
	sub vcl_deliver { set req.proto = "HTTP/1.2"; }
}

varnish v1 -errvcl "Variable is read only" {
	backend proforma None;
	sub vcl_deliver { set resp.proto = "HTTP/1.2"; }
}

varnish v1 -errvcl "Variable is read only" {
	backend proforma None;
	sub vcl_backend_response { set bereq.proto = "HTTP/1.2"; }
}

varnish v1 -errvcl "Variable is read only" {
	backend proforma None;
	sub vcl_backend_response { set beresp.proto = "HTTP/1.2"; }
}

varnish v1 -errvcl "Variable is read only" {
	backend proforma None;
	sub vcl_recv { set req.http.content-length = "42"; }
}

varnish v1 -errvcl "Variable cannot be unset" {
	backend proforma None;
	sub vcl_recv { unset req.http.content-length; }
}

server s1 {
	rxreq
	txresp -hdr "Connection: close" -body "012345\n"
}

server s1 -start

varnish v1 -syntax 4.0 -vcl+backend {
	sub vcl_recv {
		set req.http.foobar =
		    req.url +
		    req.method +
		    req.proto;
		set req.url = "/";
		set req.proto = "HTTP/1.2";
		set req.method = "GET";
	}
	sub vcl_backend_fetch {
		set bereq.http.foobar =
		    bereq.url +
		    bereq.proto;
		set bereq.url = "/";
		set bereq.proto = "HTTP/1.2";
		set bereq.method = "GET";
	}
	sub vcl_backend_response {
		set beresp.http.foobar =
		    beresp.proto + beresp.reason + beresp.status;
		set beresp.proto = "HTTP/1.2";
		set beresp.reason = "For circular files";
		set beresp.status = 903;
		set beresp.http.y-served-by-hostname = server.hostname;
		set beresp.http.y-served-by-identity = server.identity;
	}
	sub vcl_deliver {
		set resp.proto = "HTTP/1.2";
		set resp.reason = "Naah, lets fail it";
		set resp.status = 904;
		# XXX should be moved to it's own test
		set resp.http.x-served-by-hostname = server.hostname;
		set resp.http.x-served-by-identity = server.identity;
		set resp.http.foobar = resp.proto + resp.status;
	}
} -start

client c1 {
	txreq -url "/"
	rxresp
	expect resp.status == 904
}

client c1 -run

server s1 -wait

varnish v1 -stop
