VCL language preview
1. A basic VCL config
the vcl header, a backend, and vcl_recv/vcl_backend_response
horizon-dark
vcl 4.1;
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.method == "PURGE") {
return (purge);
}
set req.http.X-Forwarded-For = client.ip;
}
sub vcl_backend_response {
set beresp.ttl = 1h;
}
atom-one-dark
vcl 4.1;
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.method == "PURGE") {
return (purge);
}
set req.http.X-Forwarded-For = client.ip;
}
sub vcl_backend_response {
set beresp.ttl = 1h;
}
github-dark
vcl 4.1;
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.method == "PURGE") {
return (purge);
}
set req.http.X-Forwarded-For = client.ip;
}
sub vcl_backend_response {
set beresp.ttl = 1h;
}
dracula
vcl 4.1;
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.method == "PURGE") {
return (purge);
}
set req.http.X-Forwarded-For = client.ip;
}
sub vcl_backend_response {
set beresp.ttl = 1h;
}
nord
vcl 4.1;
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.method == "PURGE") {
return (purge);
}
set req.http.X-Forwarded-For = client.ip;
}
sub vcl_backend_response {
set beresp.ttl = 1h;
}
github
vcl 4.1;
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.method == "PURGE") {
return (purge);
}
set req.http.X-Forwarded-For = client.ip;
}
sub vcl_backend_response {
set beresp.ttl = 1h;
}
2. ACLs and caching rules
an acl block and cache control logic
horizon-dark
acl purge_allowed {
"localhost";
"192.168.0.0"/24;
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
} atom-one-dark
acl purge_allowed {
"localhost";
"192.168.0.0"/24;
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
} github-dark
acl purge_allowed {
"localhost";
"192.168.0.0"/24;
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
} dracula
acl purge_allowed {
"localhost";
"192.168.0.0"/24;
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
} nord
acl purge_allowed {
"localhost";
"192.168.0.0"/24;
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
} github
acl purge_allowed {
"localhost";
"192.168.0.0"/24;
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
} 3. Synthetic responses
vcl_synth and the synthetic function
horizon-dark
sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = req.http.X-Redirect-To;
return (deliver);
}
synthetic("Error " + resp.status);
} atom-one-dark
sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = req.http.X-Redirect-To;
return (deliver);
}
synthetic("Error " + resp.status);
} github-dark
sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = req.http.X-Redirect-To;
return (deliver);
}
synthetic("Error " + resp.status);
} dracula
sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = req.http.X-Redirect-To;
return (deliver);
}
synthetic("Error " + resp.status);
} nord
sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = req.http.X-Redirect-To;
return (deliver);
}
synthetic("Error " + resp.status);
} github
sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = req.http.X-Redirect-To;
return (deliver);
}
synthetic("Error " + resp.status);
}