[#2497] Added Cache-Control response header for media proxy preview endpoint.
authorIvan Tashkinov <ivantashkinov@gmail.com>
Mon, 31 Aug 2020 10:08:50 +0000 (13:08 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Mon, 31 Aug 2020 10:08:50 +0000 (13:08 +0300)
lib/pleroma/web/media_proxy/media_proxy_controller.ex

index 94fae6cac571f7c1de9adddde1b9374ab695cf8e..2afcd861afc03645331df3e71147d27bf25f9440 100644 (file)
@@ -107,8 +107,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
              }
            ) do
       conn
-      |> put_resp_header("content-type", "image/png")
-      |> put_resp_header("content-disposition", "inline; filename=\"preview.png\"")
+      |> put_preview_response_headers()
       |> send_resp(200, thumbnail_binary)
     else
       _ ->
@@ -126,8 +125,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
              %{max_width: thumbnail_max_width, max_height: thumbnail_max_height, quality: quality}
            ) do
       conn
-      |> put_resp_header("content-type", "image/jpeg")
-      |> put_resp_header("content-disposition", "inline; filename=\"preview.jpg\"")
+      |> put_preview_response_headers()
       |> send_resp(200, thumbnail_binary)
     else
       _ ->
@@ -139,8 +137,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
     with {:ok, thumbnail_binary} <-
            MediaHelper.video_framegrab(url) do
       conn
-      |> put_resp_header("content-type", "image/jpeg")
-      |> put_resp_header("content-disposition", "inline; filename=\"preview.jpg\"")
+      |> put_preview_response_headers()
       |> send_resp(200, thumbnail_binary)
     else
       _ ->
@@ -148,6 +145,13 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
     end
   end
 
+  defp put_preview_response_headers(conn) do
+    conn
+    |> put_resp_header("content-type", "image/jpeg")
+    |> put_resp_header("content-disposition", "inline; filename=\"preview.jpg\"")
+    |> put_resp_header("cache-control", "max-age=0, private, must-revalidate")
+  end
+
   defp thumbnail_max_dimensions(params) do
     config = Config.get([:media_preview_proxy], [])