In vcl_synth I am trying to craft modified error pages; I may move this to vcl_backend_error, but that is moot as the problem remains the same. I am using CentOS 7, so only have access to 4.0, not 4.1. This is important as std.file_exists only exists in >= 4.1. It is unacceptable to use packages from untrusted, untested, sources that break forwards/backwards compatibility.
To handle issues where the 503.html file may not exist I would like to test the synthetic output, and if null/empty generate a fallback error page. For debugging I'm throwing all output to syslog; this will not persist to production, in its current form.
Sample:
sub vcl_synth {
if (resp.status == 503) {
set resp.http.Content-Type = "text/html; charset=utf-8";
synthetic(std.fileread("/var/www/vhost/" + req.http.host + "/error/503.html"));
std.syslog(3, "resp.http.body: " + resp.http.body);
return (deliver);
}
}
With the above I clearly see that resp.http.body is empty, but the page is returned and renders in my browser. So, if it does, which variable does synthetic set? And, can it be tested?
# journalctl -f
...
Sep 08 02:17:17 REDACTED_HOSTNAME varnishd[32498]: resp.http.body:
pls halp
Execution of
synthetic(...)
duringvcl_synth
does not populateresp.http.body
. That's just a random header name. One possible approach would be to populate a 'temporary variable' with the response body: