aboutsummaryrefslogtreecommitdiffstats
path: root/extras/misc/varnish.vcl
blob: c9e23c598c0ed3fd0859deed69ab2de28beb21fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# vim: ts=8:expandtab:sw=4:softtabstop=4

vcl 4.0;

backend default {
    .host = "gondul-front";
    .port = "80";
}

backend graphite {
    .host = "gondul-graphite";
    .port = "80";
}

backend templating {
    .host = "gondul-templating";
    .port = "8080";
}

sub vcl_recv {
    if (req.url ~ "^/where" || req.url ~ "^/location") {
	set req.url = "/api/public/location";
    }
    if (req.method != "GET" &&
        req.method != "HEAD" &&
        req.method != "PUT" &&
        req.method != "POST" &&
        req.method != "TRACE" &&
        req.method != "OPTIONS" &&
        req.method != "DELETE") {
        # Vi hater alt som er gøy.
        return (synth(418,"LOLOLOL"));
    }

    if (req.method != "GET" && req.method != "HEAD") {
        /* We only deal with GET and HEAD by default */
        return (pass);
    }

    if (req.url ~ "/render") {
        set req.backend_hint = graphite;
    }
    if (req.url ~ "/templating") {
        set req.url = regsub(req.url, "/templating", "");
        set req.backend_hint = templating;
    }

    # Brukes ikke. Cookies er for nubs.
    unset req.http.Cookie;

    # Tvinges gjennom for å cache med authorization-skrot.
    return (hash);
}


# Rosa magi
sub vcl_hash {
    # Wheee. Legg til authorization-headeren i hashen.
    hash_data(req.http.authorization);
}

# Mauve magi. Hva nå enn det er.
# Dette er WIP - Skal flyttes til backend
sub vcl_backend_response {
    set beresp.http.x-url = bereq.url;
    if (beresp.http.x-ban) {
        ban("obj.http.x-url ~ " + beresp.http.x-ban);
    }
    if (bereq.url ~ "/render") {
        # Graphite claims "no-cache", which is dumb.
        # Let's blindly cache for 5+10s. Which is 10000 times better.
        set beresp.http.Cache-Control = "max-age=5s";
        unset beresp.http.Pragma;
        set beresp.uncacheable = false;
        set beresp.grace = 10s;
        set beresp.ttl = 5s;
    }
    if (beresp.status != 200) {
        set beresp.uncacheable = false;
        set beresp.ttl = 5s;
    }
    if (bereq.url ~ "\.(html|css|js)") {
        # Mainly for ease of development
        set beresp.ttl = 10s;
    }
}