X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=examples%2Fvarnish-4.vcl;h=24296032741fe18df2d90122d5b314a25acf6f5d;hb=292ca34140489da2c3458e1d45da5a9ae4af540d;hp=7439679de35f89f5f746efdf04468d74396e0483;hpb=50b0c766e5d9b3fac17d7fe0f2089a89af1aa777;p=public-inbox.git diff --git a/examples/varnish-4.vcl b/examples/varnish-4.vcl index 7439679d..24296032 100644 --- a/examples/varnish-4.vcl +++ b/examples/varnish-4.vcl @@ -10,32 +10,15 @@ vcl 4.0; backend default { + # this is where public-inbox-http listens .host = "127.0.0.1"; .port = "280"; } sub vcl_recv { - if (req.restarts == 0) { - if (req.http.x-forwarded-for) { - set req.http.X-Forwarded-For = - req.http.X-Forwarded-For + ", " + client.ip; - } else { - set req.http.X-Forwarded-For = client.ip; - } - } - if (req.method != "GET" && - req.method != "HEAD" && - req.method != "PUT" && - req.method != "POST" && - req.method != "TRACE" && - req.method != "OPTIONS" && - req.method != "DELETE") { - /* Non-RFC2616 or CONNECT which is weird. */ - return (pipe); - } + /* pipe POST and any other weird methods directly to backend */ if (req.method != "GET" && req.method != "HEAD") { - /* We only deal with GET and HEAD by default */ - return (pass); + return (pipe); } if (req.http.Authorization || req.http.Cookie) { /* Not cacheable by default */ @@ -44,6 +27,13 @@ sub vcl_recv { return (hash); } +sub vcl_pipe { + # By default Connection: close is set on all piped requests by varnish, + # but public-inbox-httpd supports persistent connections well :) + unset bereq.http.connection; + return (pipe); +} + sub vcl_hash { hash_data(req.url); if (req.http.host) { @@ -51,6 +41,7 @@ sub vcl_hash { } else { hash_data(server.ip); } + /* we generate fully-qualified URLs for Atom feeds and redirects */ if (req.http.X-Forwarded-Proto) { hash_data(req.http.X-Forwarded-Proto); } @@ -61,6 +52,8 @@ sub vcl_backend_response { set beresp.grace = 60s; set beresp.do_stream = true; if (beresp.ttl <= 0s || + /* no point in caching stuff git already stores on disk */ + beresp.http.Content-Type ~ "application/x-git" || beresp.http.Set-Cookie || beresp.http.Vary == "*") { /* Mark as "Hit-For-Pass" for the next 2 minutes */ @@ -68,6 +61,7 @@ sub vcl_backend_response { set beresp.uncacheable = true; return (deliver); } else { + /* short TTL for up-to-dateness, our PSGI is not that slow */ set beresp.ttl = 10s; } return (deliver);