Which variable does 'synthetic' set in Varnish 4?

508 views Asked by At

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

2

There are 2 answers

1
Carlos Abalde On

Execution of synthetic(...) during vcl_synth does not populate resp.http.body. That's just a random header name. One possible approach would be to populate a 'temporary variable' with the response body:

sub vcl_synth {
    if (resp.status == 503) {
        set resp.http.Content-Type = "text/html; charset=utf-8";
        set req.http.X-Synth-Body = std.fileread("/var/www/vhost/" + req.http.host + "/error/503.html");
        synthetic(req.http.X-Synth-Body);
        std.syslog(3, "req.http.X-Synth-Body: " + req.http.X-Synth-Body);
        return (deliver);
    }
}
1
Danila Vershinin On

Regarding the:

It is unacceptable to use packages from untrusted, untested, sources that break forwards/backwards compatibility.

Varnish has a dedicated repository for 4.1.

Those packages are signed, specific to 4.1 branch only and should not break forward/backward compatibility.

Plus, since you're using their software you essentially already trust them. Moreover, there are recent security updates that might make it faster to their repository and not the EPEL, etc.

And Varnish 4.0 is officially EOL.