1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.WebFinger.WebFingerController do
6 use Pleroma.Web, :controller
8 alias Pleroma.Web.WebFinger
10 plug(Pleroma.Web.Plugs.SetFormatPlug)
11 plug(Pleroma.Web.Plugs.FederatingPlug)
13 def host_meta(conn, _params) do
14 xml = WebFinger.host_meta()
17 |> put_resp_content_type("application/xrd+xml")
18 |> send_resp(200, xml)
21 def webfinger(%{assigns: %{format: format}} = conn, %{"resource" => resource})
22 when format in ["xml", "xrd+xml"] do
23 with {:ok, response} <- WebFinger.webfinger(resource, "XML") do
25 |> put_resp_content_type("application/xrd+xml")
26 |> send_resp(200, response)
28 _e -> send_resp(conn, 404, "Couldn't find user")
32 def webfinger(%{assigns: %{format: format}} = conn, %{"resource" => resource})
33 when format in ["json", "jrd+json"] do
34 with {:ok, response} <- WebFinger.webfinger(resource, "JSON") do
39 |> put_status(:not_found)
40 |> json("Couldn't find user")
44 def webfinger(conn, _params), do: send_resp(conn, 400, "Bad Request")