Much of the VCL syntax has changed in Varnish 4. We've tried to compile a list of changes needed to upgrade here.
To make sure that people have upgraded their VCL to the current version, Varnish now requires the first line of VCL to indicate the VCL version number:
vcl 4.0;
To make directors (backend selection logic) easier to extend, the directors are now defined in loadable VMODs.
Setting a backend for future fetches in vcl_recv is now done as follows:
sub vcl_init {
new cluster1 = directors.round_robin();
cluster1.add_backend(b1, 1.0);
cluster1.add_backend(b2, 1.0);
}
sub vcl_recv {
set req.backend_hint = cluster1.backend();
}
Note the extra .backend() needed after the director name.
Since the client director was already a special case of the hash director, it has been removed, and you should use the hash director directly:
sub vcl_init {
new h = directors.hash();
h.add_backend(b1, 1);
h.add_backend(b2, 1);
}
sub vcl_recv {
set req.backend_hint = h.backend(client.identity);
}
Setting headers on synthetic response bodies made in vcl_synth are now done on resp.http instead of obj.http.
The synthetic keyword is now a function:
if (resp.status == 799) {
set resp.status = 200;
set resp.http.Content-Type = "text/plain; charset=utf-8";
synthetic("You are " + client.ip);
return (deliver);
}
Example:
sub vcl_backend_response {
if (beresp.http.X-No-Cache) {
set beresp.uncacheable = true;
set beresp.ttl = 120s;
return (deliver);
}
}
req.* used to be available in vcl_fetch, but after the split of functionality, you only have 'bereq.*' in vcl_backend_response.
Any custom-made subs cannot be named 'vcl_*' anymore. This namespace is reserved for builtin subs.
obj is now read-only. obj.hits, if enabled in VCL, now counts per objecthead, not per object. obj.last_use has been retired.
The VCL code that is appended to user-configured VCL automatically is now called the builtin VCL. (previously default.vcl)
The builtin VCL now honors Cache-Control: no-cache (and friends) to indicate uncacheable content from the backend.
Replaced by unset.
In 3.0 it was often necessary to increase sess_workspace if a lot of VMODs, complex header operations or ESI were in use.
This memory segment has been split into two in 4.0; workspace_backend and workspace_client.
In most cases where you increased sess_workspace before, you want to increase workspace_client now.
This parameter is new since 3.0, and prohibits the use of inline C code in VCL by default.