From fda942c329696fc44d3671c5ca58a28c3c38f50a Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 10 Jan 2019 18:28:14 +0000 Subject: [PATCH] Cache partial objects for 10 minutes This enables caching/streaming of chunked responses --- installation/pleroma.vcl | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/installation/pleroma.vcl b/installation/pleroma.vcl index ca79eb7fc..30e552411 100644 --- a/installation/pleroma.vcl +++ b/installation/pleroma.vcl @@ -18,6 +18,11 @@ sub vcl_recv { return (synth(750, "")); } + # CHUNKED SUPPORT + if (req.http.Range ~ "bytes=") { + set req.http.x-range = req.http.Range; + } + # Pipe if WebSockets request is coming through if (req.http.upgrade ~ "(?i)websocket") { return (pipe); @@ -56,6 +61,12 @@ sub vcl_backend_response { set beresp.do_gzip = true; } + # CHUNKED SUPPORT + if (bereq.http.x-range ~ "bytes=" && beresp.status == 206) { + set beresp.ttl = 10m; + set beresp.http.CR = beresp.http.content-range; + } + # Don't cache objects that require authentication if (beresp.http.Authorization && !beresp.http.Cache-Control ~ "public") { set beresp.uncacheable = true; @@ -111,3 +122,26 @@ sub vcl_pipe { set bereq.http.connection = req.http.connection; } } + +sub vcl_hash { + # CHUNKED SUPPORT + if (req.http.x-range ~ "bytes=") { + hash_data(req.http.x-range); + unset req.http.Range; + } +} + +sub vcl_backend_fetch { + # CHUNKED SUPPORT + if (bereq.http.x-range) { + set bereq.http.Range = bereq.http.x-range; + } +} + +sub vcl_deliver { + # CHUNKED SUPPORT + if (resp.http.CR) { + set resp.http.Content-Range = resp.http.CR; + unset resp.http.CR; + } +}