Set correct Cache-Control header for local media
authorMark Felder <feld@FreeBSD.org>
Fri, 13 Mar 2020 17:02:58 +0000 (12:02 -0500)
committerMark Felder <feld@FreeBSD.org>
Fri, 13 Mar 2020 17:02:58 +0000 (12:02 -0500)
lib/pleroma/plugs/uploaded_media.ex

index f372829a2b0358f67f680c227d7c84f89ae5b294..57097baaeaed701fed431f96fc4e1974f8a5395a 100644 (file)
@@ -14,6 +14,8 @@ defmodule Pleroma.Plugs.UploadedMedia do
   # no slashes
   @path "media"
 
+  @default_cache_control_header "public max-age=86400 must-revalidate"
+
   def init(_opts) do
     static_plug_opts =
       []
@@ -58,6 +60,10 @@ defmodule Pleroma.Plugs.UploadedMedia do
       Map.get(opts, :static_plug_opts)
       |> Map.put(:at, [@path])
       |> Map.put(:from, directory)
+      |> Map.put(:cache_control_for_etags, @default_cache_control_header)
+      |> Map.put(:headers, %{
+        "cache-control" => @default_cache_control_header
+      })
 
     conn = Plug.Static.call(conn, static_opts)