Cache partial objects for 10 minutes
authorMark Felder <feld@FreeBSD.org>
Thu, 10 Jan 2019 18:28:14 +0000 (18:28 +0000)
committerMark Felder <feld@FreeBSD.org>
Thu, 10 Jan 2019 18:28:14 +0000 (18:28 +0000)
This enables caching/streaming of chunked responses

installation/pleroma.vcl

index ca79eb7fc4ef8d9b3cf406ecb89fcc4b3d6bca43..30e552411f8045bead62b08c9100365dee144178 100644 (file)
@@ -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;
+    }
+}