StaticFE: Prioritize json in requests.

This commit is contained in:
lain 2020-06-26 16:27:39 +02:00
commit a5bbfa21a1
2 changed files with 21 additions and 4 deletions

View file

@ -9,7 +9,7 @@ defmodule Pleroma.Plugs.StaticFEPlug do
def init(options), do: options
def call(conn, _) do
if enabled?() and accepts_html?(conn) do
if enabled?() and requires_html?(conn) do
conn
|> StaticFEController.call(:show)
|> halt()
@ -20,10 +20,13 @@ defmodule Pleroma.Plugs.StaticFEPlug do
defp enabled?, do: Pleroma.Config.get([:static_fe, :enabled], false)
defp accepts_html?(conn) do
defp requires_html?(conn) do
case get_req_header(conn, "accept") do
[accept | _] -> String.contains?(accept, "text/html")
_ -> false
[accept | _] ->
!String.contains?(accept, "json") && String.contains?(accept, "text/html")
_ ->
false
end
end
end