diff --git a/lib/web/controllers/activity_pub_controller.ex b/lib/web/controllers/activity_pub_controller.ex index 93f13282..2d97e4a5 100644 --- a/lib/web/controllers/activity_pub_controller.ex +++ b/lib/web/controllers/activity_pub_controller.ex @@ -85,8 +85,9 @@ defmodule Mobilizon.Web.ActivityPubController do actor = Map.get(conn.assigns, :actor) if actor_applicant_group_member?(group, actor) do - json( - conn, + conn + |> put_resp_content_type("application/activity+json") + |> json( ActorView.render("member.json", %{ member: member, actor_applicant: actor @@ -168,7 +169,7 @@ defmodule Mobilizon.Web.ActivityPubController do def relay(conn, _params) do with {status, %Actor{} = actor} when status in [:commit, :ok] <- Cache.get_relay() do conn - |> put_resp_header("content-type", "application/activity+json") + |> put_resp_content_type("application/activity+json") |> json(ActorView.render("actor.json", %{actor: actor})) end end @@ -194,7 +195,7 @@ defmodule Mobilizon.Web.ActivityPubController do page <- max(page, 1), %Actor{} = actor <- Actors.get_local_actor_by_name_with_preload(name) do conn - |> put_resp_header("content-type", "application/activity+json") + |> put_resp_content_type("application/activity+json") |> json( ActorView.render("#{collection}.json", %{ actor: actor, @@ -208,7 +209,7 @@ defmodule Mobilizon.Web.ActivityPubController do defp actor_collection(conn, collection, %{"name" => name}) do with %Actor{} = actor <- Actors.get_local_actor_by_name_with_preload(name) do conn - |> put_resp_header("content-type", "application/activity+json") + |> put_resp_content_type("application/activity+json") |> json( ActorView.render("#{collection}.json", %{ actor: actor, diff --git a/lib/web/controllers/page_controller.ex b/lib/web/controllers/page_controller.ex index cc00560a..9afb1f77 100644 --- a/lib/web/controllers/page_controller.ex +++ b/lib/web/controllers/page_controller.ex @@ -141,11 +141,13 @@ defmodule Mobilizon.Web.PageController do %Tombstone{} -> conn |> put_status(:gone) + |> maybe_add_content_type_header() |> render(object_type, object: object) _ -> conn |> maybe_add_noindex_header(object) + |> maybe_add_content_type_header() |> render(object_type, object: object) end @@ -199,4 +201,14 @@ defmodule Mobilizon.Web.PageController do @spec is_person?(Actor.t()) :: boolean() defp is_person?(%Actor{type: :Person}), do: true 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