I agree to Michael's short response to abuse/use vcl_error for this purpose and like to show you what we meant in the example code below.
To abuse vcl_error I have used here error codes outside of the HTTP standard and implement a special treatment for this kind of errors.
Example in VCL_RECV:
sub vcl_recv {
...
# respond HTTP 200 to /ping requests
if (req.url ~ "^/ping") {
error 700;
}
# return a 301 redirect
if (req.url ~ "^/wrong-target") {
error 751 "http://www.example.com/correct-target";
}
}
Example in VCL_ERROR:
sub vcl_error {
# send response "Pong" (HTTP 200)
if (obj.status == 700) {
set obj.status = 200;
set obj.response = "OK";
set obj.http.Content-Type = "text/plain";
synthetic {"Pong"};
return (deliver);
}
# send empty response (HTTP 204)
if (obj.status == 701) {
set obj.status = 204;
set obj.response = "No Content";
synthetic {""};
return (deliver);
}
# redirect 301
if (obj.status == 751) {
set obj.http.Location = obj.response;
set obj.status = 301;
set obj.response = "Moved Permanently";
return (deliver);
}
# redirect 302
if (obj.status == 752) {
set obj.http.Location = obj.response;
set obj.status = 302;
set obj.response = "Found";
return (deliver);
}
# Fall through to default behavior for all other exceptions
}
vcl_error
to do this.