vtest "set VCL_??? [+]= VCL_???;"

# set STRING|HEADER += STRINGS;

server s1 {
	rxreq
	expect req.url == "/hello/world"
	expect req.http.host == helloworld
	txresp -hdr "x-powered-by: vinyltest"
} -start

vinyl v1 -vcl+backend {
	sub vcl_backend_fetch {
		set bereq.url += "/world";
		set bereq.http.host += "world";
	}
	sub vcl_backend_response {
		set beresp.http.x-powered-by += bereq.http.X-Vinyl;
	}
} -start

client c1 {
	txreq -url "/hello" -hdr "host: hello"
	rxresp
	expect resp.status == 200
	expect resp.http.x-powered-by == vinyltest1002
} -run

# set BODY [+]= STRINGS|BLOB;

vinyl v1 -vcl {
	import blob;
	backend be none;
	sub vcl_recv {
		return (synth(200));
	}
	sub vcl_synth {
		if (req.url ~ "synth") {
			synthetic("hello");
			if (req.url ~ "add") {
				synthetic("world");
			}
		}
		if (req.url ~ "string") {
			set resp.body = "hello";
			if (req.url ~ "reset") {
				set resp.body = "world";
			}
			if (req.url ~ "add") {
				set resp.body += "world";
			}
		}
		if (req.url ~ "blob/literal") {
			set resp.body = :aGVsbG93b3JsZA==:;
		} elif (req.url ~ "blob") {
			set resp.body = blob.decode(HEX, encoded="1100");
			if (req.url ~ "reset") {
				set resp.body = blob.decode(HEX, encoded="221100");
			}
			if (req.url ~ "add") {
				set resp.body += blob.decode(HEX, encoded="221100");
			}
		}
		return (deliver);
	}
}

client c2 {
	txreq -url "/synth"
	rxresp
	expect resp.body == hello

	txreq -url "/synth/add"
	rxresp
	expect resp.body == helloworld

	txreq -url "/string"
	rxresp
	expect resp.body == hello

	txreq -url "/string/reset"
	rxresp
	expect resp.body == world

	txreq -url "/string/add"
	rxresp
	expect resp.body == helloworld

	txreq -url "/blob"
	rxresp
	expect resp.bodylen == 2

	txreq -url "/blob/reset"
	rxresp
	expect resp.bodylen == 3

	txreq -url "/blob/add"
	rxresp
	expect resp.bodylen == 5

	txreq -url "/blob/literal"
	rxresp
	expect resp.body == helloworld
} -run
