NOVCL: AN ALTERNATIVE TO VCL

VCL is so good it can replace itself

The helicopter view

Backend file

192.168.12.34
staging-pool.example.com

Rules file

prefix "/supersecret/" "block"    "404"
prefix "/admin/" "pass"
regex "^/static/(.*)" "redirect" "301" "static.example.com/\1"
suffix ".jpg" "cache" "5m" "1h" "2d"
suffix ".js" "cache" "1m"

VCL file

vcl 4.0;import goto;
import rewrite;
import std;
import urlplus;
backend fake_be { .host = "0"; }sub vcl_init {
new director = goto.dns_director(std.fileread("/tmp/backend"));
new ruleset = rewrite.ruleset("/tmp/ruleset", type = any);
}
sub vcl_recv {
set req.backend_hint = director.backend();
unset req.http.location; if (ruleset.match(urlplus.url_as_string())) {
set req.http.command = ruleset.rewrite(field = 2, mode = only_matching);
} else {
set req.http.command = "default";
}
if (req.http.command == "block") {
return (synth(std.integer(ruleset.rewrite(field = 3, mode = only_matching), 404)));
} else if (req.http.command == "pass") {
return (pass);
} else if (req.http.command == "redirect") {
set req.http.location = ruleset.rewrite(field = 4);
return (synth(std.integer(ruleset.rewrite(field = 3, mode = only_matching), 301)));
} else if (req.http.command == "cache") {
unset req.http.cookie;
} else {
set req.http.command = "default";
}
}
sub vcl_backend_response {
if (bereq.uncacheable) {
return (deliver);
} else if (bereq.http.command == "cache") {
ruleset.match(urlplus.url_as_string());
set beresp.ttl = std.duration(ruleset.rewrite(field = 3, mode = only_matching), 2m);
set beresp.grace = std.duration(ruleset.rewrite(field = 4, mode = only_matching), 0s);
set beresp.keep = std.duration(ruleset.rewrite(field = 5, mode = only_matching), 1h);
unset beresp.http.set-cookie;
}
}
sub vcl_synth {
if (req.http.location) {
set resp.http.location = req.http.location;
return (deliver);
}
}

Notable details

regextable? matchmap?

Type conversion

suffix ".jpg"          "cache"    "5m" "1h" "2d"
suffix ".js" "cache" "1m"

Fake one until you can make one

backend fake_be { .host = "0"; }

Logging

varnishncsa -F '%{command}i %U %s'
varnishncsa -F%{VSL:RespHeader:x-cache[1]}x '%{command}i %U %s'

Drawing the line

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store