]> git.sesse.net Git - remoteglot/blob - default.vcl
Do not bold anything when there is no running clock.
[remoteglot] / default.vcl
1 // Varnish configuration snippets.
2
3 vcl 4.0;
4
5 backend analysis {
6     .host = "127.0.0.1";
7     .port = "5000";
8 }
9
10 sub vcl_recv {
11     if (req.restarts == 0) {
12         if (req.http.x-forwarded-for) {
13             set req.http.X-Forwarded-For =
14                 req.http.X-Forwarded-For + ", " + client.ip;
15         } else {
16             set req.http.X-Forwarded-For = client.ip;
17         }
18     }
19     if (req.http.host ~ "analysis\.sesse\.net$" && req.url ~ "^/analysis\.pl") {
20         set req.backend_hint = analysis;
21         return (hash);
22     }
23 }
24
25 sub vcl_deliver { 
26     if (resp.http.x-analysis) {
27         set resp.http.date = now;
28     }
29     unset resp.http.x-analysis;
30 }
31
32 sub vcl_hash {
33     hash_data(regsub(req.url, "unique=.*$", ""));
34     if (req.http.host) {
35         hash_data(req.http.host);
36     } else {
37         hash_data(server.ip);
38     }
39     return (lookup);
40 }
41
42 sub vcl_backend_response {
43     if (bereq.http.host ~ "analysis") {
44         set beresp.ttl = 1m;
45         if (beresp.http.content-type ~ "text" || beresp.http.content-type ~ "json") {
46              set beresp.do_gzip = true;
47         }
48         if (beresp.http.content-type ~ "json") {
49              set beresp.http.x-analysis = 1;
50              ban ( "obj.http.x-analysis == 1 && obj.http.x-remoteglot-last-modified != " + beresp.http.x-remoteglot-last-modified );
51         }
52         return (deliver);
53     }
54 }