reprogl
1vcl 4.0;
2
3import std;
4
5backend default {
6.host = "gopher";
7.port = "8080";
8}
9
10sub vcl_recv {
11if (req.method == "POST" && req.url == "/purge-cache") {
12if (req.http.x-ban-token == std.getenv("BAN_TOKEN")) {
13std.ban("req.http.host ~ .*");
14} else {
15return (synth(403, "Forbidden"));
16}
17}
18
19if (req.http.Cookie) {
20if (req.http.Cookie ~ ".*(^|;| )?session=([a-zA-Z0-9\-_=]+)( |;|$)?.*") {
21set req.http.X-Varnish-Session = regsub(req.http.Cookie, ".*(^|;| )?session=([a-zA-Z0-9\-_=]+)( |;|$)?.*", "\2");
22}
23
24if (!(req.url ~ "^/login" || req.url ~ "^/oauth")) {
25unset req.http.Cookie;
26}
27}
28}
29
30sub vcl_backend_response {
31if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
32unset beresp.http.Surrogate-Control;
33set beresp.do_esi = true;
34}
35}
36
37sub vcl_hash {
38hash_data(req.url);
39if (req.http.X-Varnish-Session && (
40req.url == "/_fragment/auth-navigation" ||
41req.url == "/_fragment/menu-auth" ||
42req.url ~ "^/_fragment/comments/")
43) {
44hash_data(req.http.X-Varnish-Session);
45}
46
47if (req.http.Via && (
48req.url == "/robots.txt" ||
49req.url == "/sitemap.xml")
50) {
51hash_data(req.http.Via);
52}
53
54return (lookup);
55}
56
57sub vcl_deliver {
58unset resp.http.Age;
59unset resp.http.Via;
60unset resp.http.X-Varnish;
61}
62