]> git.sesse.net Git - remoteglot/blob - default.vcl
Add a small explanatory comment.
[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         unset resp.http.X-Varnish;
29         unset resp.http.Via;
30         unset resp.http.Age;
31         unset resp.http.X-Powered-By;
32     }
33     unset resp.http.x-analysis;
34 }
35
36 sub vcl_hash {
37     hash_data(regsub(req.url, "unique=.*$", ""));
38     if (req.http.host) {
39         hash_data(req.http.host);
40     } else {
41         hash_data(server.ip);
42     }
43     return (lookup);
44 }
45
46 sub vcl_backend_response {
47     if (bereq.http.host ~ "analysis") {
48         set beresp.ttl = 1m;
49         if (beresp.http.content-type ~ "text" || beresp.http.content-type ~ "json") {
50              set beresp.do_gzip = true;
51         }
52         if (beresp.http.content-type ~ "json") {
53              set beresp.http.x-analysis = 1;
54              ban ( "obj.http.x-analysis == 1 && obj.http.x-rglm != " + beresp.http.x-rglm );
55         }
56         return (deliver);
57     }
58 }