Merge branch 'feature/static-headers' into 'develop'
Improve serving of static assets See merge request pleroma/pleroma!1200
This commit is contained in:
commit
8a0ee011ac
@ -16,17 +16,32 @@ defmodule Pleroma.Web.Endpoint do
|
|||||||
|
|
||||||
plug(Pleroma.Plugs.UploadedMedia)
|
plug(Pleroma.Plugs.UploadedMedia)
|
||||||
|
|
||||||
|
@static_cache_control "public, no-cache"
|
||||||
|
|
||||||
# InstanceStatic needs to be before Plug.Static to be able to override shipped-static files
|
# InstanceStatic needs to be before Plug.Static to be able to override shipped-static files
|
||||||
# If you're adding new paths to `only:` you'll need to configure them in InstanceStatic as well
|
# If you're adding new paths to `only:` you'll need to configure them in InstanceStatic as well
|
||||||
plug(Pleroma.Plugs.InstanceStatic, at: "/")
|
# Cache-control headers are duplicated in case we turn off etags in the future
|
||||||
|
plug(Pleroma.Plugs.InstanceStatic,
|
||||||
|
at: "/",
|
||||||
|
gzip: true,
|
||||||
|
cache_control_for_etags: @static_cache_control,
|
||||||
|
headers: %{
|
||||||
|
"cache-control" => @static_cache_control
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
plug(
|
plug(
|
||||||
Plug.Static,
|
Plug.Static,
|
||||||
at: "/",
|
at: "/",
|
||||||
from: :pleroma,
|
from: :pleroma,
|
||||||
only:
|
only:
|
||||||
~w(index.html robots.txt static finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc)
|
~w(index.html robots.txt static finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc),
|
||||||
# credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
|
# credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
|
||||||
|
gzip: true,
|
||||||
|
cache_control_for_etags: @static_cache_control,
|
||||||
|
headers: %{
|
||||||
|
"cache-control" => @static_cache_control
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
plug(Plug.Static.IndexHtml, at: "/pleroma/admin/")
|
plug(Plug.Static.IndexHtml, at: "/pleroma/admin/")
|
||||||
|
20
test/plugs/cache_control_test.exs
Normal file
20
test/plugs/cache_control_test.exs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.CacheControlTest do
|
||||||
|
use Pleroma.Web.ConnCase
|
||||||
|
alias Plug.Conn
|
||||||
|
|
||||||
|
test "Verify Cache-Control header on static assets", %{conn: conn} do
|
||||||
|
conn = get(conn, "/index.html")
|
||||||
|
|
||||||
|
assert Conn.get_resp_header(conn, "cache-control") == ["public, no-cache"]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "Verify Cache-Control header on the API", %{conn: conn} do
|
||||||
|
conn = get(conn, "/api/v1/instance")
|
||||||
|
|
||||||
|
assert Conn.get_resp_header(conn, "cache-control") == ["max-age=0, private, must-revalidate"]
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user