Set correct Content-Type on all AP endpoints
Closes #1210 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
2e9414767c
commit
aeaf22a224
@ -85,8 +85,9 @@ defmodule Mobilizon.Web.ActivityPubController do
|
|||||||
actor = Map.get(conn.assigns, :actor)
|
actor = Map.get(conn.assigns, :actor)
|
||||||
|
|
||||||
if actor_applicant_group_member?(group, actor) do
|
if actor_applicant_group_member?(group, actor) do
|
||||||
json(
|
conn
|
||||||
conn,
|
|> put_resp_content_type("application/activity+json")
|
||||||
|
|> json(
|
||||||
ActorView.render("member.json", %{
|
ActorView.render("member.json", %{
|
||||||
member: member,
|
member: member,
|
||||||
actor_applicant: actor
|
actor_applicant: actor
|
||||||
@ -168,7 +169,7 @@ defmodule Mobilizon.Web.ActivityPubController do
|
|||||||
def relay(conn, _params) do
|
def relay(conn, _params) do
|
||||||
with {status, %Actor{} = actor} when status in [:commit, :ok] <- Cache.get_relay() do
|
with {status, %Actor{} = actor} when status in [:commit, :ok] <- Cache.get_relay() do
|
||||||
conn
|
conn
|
||||||
|> put_resp_header("content-type", "application/activity+json")
|
|> put_resp_content_type("application/activity+json")
|
||||||
|> json(ActorView.render("actor.json", %{actor: actor}))
|
|> json(ActorView.render("actor.json", %{actor: actor}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -194,7 +195,7 @@ defmodule Mobilizon.Web.ActivityPubController do
|
|||||||
page <- max(page, 1),
|
page <- max(page, 1),
|
||||||
%Actor{} = actor <- Actors.get_local_actor_by_name_with_preload(name) do
|
%Actor{} = actor <- Actors.get_local_actor_by_name_with_preload(name) do
|
||||||
conn
|
conn
|
||||||
|> put_resp_header("content-type", "application/activity+json")
|
|> put_resp_content_type("application/activity+json")
|
||||||
|> json(
|
|> json(
|
||||||
ActorView.render("#{collection}.json", %{
|
ActorView.render("#{collection}.json", %{
|
||||||
actor: actor,
|
actor: actor,
|
||||||
@ -208,7 +209,7 @@ defmodule Mobilizon.Web.ActivityPubController do
|
|||||||
defp actor_collection(conn, collection, %{"name" => name}) do
|
defp actor_collection(conn, collection, %{"name" => name}) do
|
||||||
with %Actor{} = actor <- Actors.get_local_actor_by_name_with_preload(name) do
|
with %Actor{} = actor <- Actors.get_local_actor_by_name_with_preload(name) do
|
||||||
conn
|
conn
|
||||||
|> put_resp_header("content-type", "application/activity+json")
|
|> put_resp_content_type("application/activity+json")
|
||||||
|> json(
|
|> json(
|
||||||
ActorView.render("#{collection}.json", %{
|
ActorView.render("#{collection}.json", %{
|
||||||
actor: actor,
|
actor: actor,
|
||||||
|
@ -141,11 +141,13 @@ defmodule Mobilizon.Web.PageController do
|
|||||||
%Tombstone{} ->
|
%Tombstone{} ->
|
||||||
conn
|
conn
|
||||||
|> put_status(:gone)
|
|> put_status(:gone)
|
||||||
|
|> maybe_add_content_type_header()
|
||||||
|> render(object_type, object: object)
|
|> render(object_type, object: object)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
conn
|
conn
|
||||||
|> maybe_add_noindex_header(object)
|
|> maybe_add_noindex_header(object)
|
||||||
|
|> maybe_add_content_type_header()
|
||||||
|> render(object_type, object: object)
|
|> render(object_type, object: object)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -199,4 +201,14 @@ defmodule Mobilizon.Web.PageController do
|
|||||||
@spec is_person?(Actor.t()) :: boolean()
|
@spec is_person?(Actor.t()) :: boolean()
|
||||||
defp is_person?(%Actor{type: :Person}), do: true
|
defp is_person?(%Actor{type: :Person}), do: true
|
||||||
defp is_person?(_), do: false
|
defp is_person?(_), do: false
|
||||||
|
|
||||||
|
defp maybe_add_content_type_header(conn) do
|
||||||
|
case get_format(conn) do
|
||||||
|
"html" ->
|
||||||
|
conn
|
||||||
|
|
||||||
|
"activity-json" ->
|
||||||
|
put_resp_content_type(conn, "application/activity+json")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user