1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 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.FederatingPlug)
12 def host_meta(conn, _params) do
13 xml = WebFinger.host_meta()
16 |> put_resp_content_type("application/xrd+xml")
17 |> send_resp(200, xml)
20 def webfinger(conn, %{"resource" => resource}) do
21 case get_format(conn) do
22 n when n in ["xml", "xrd+xml"] ->
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")
31 n when n in ["json", "jrd+json"] ->
32 with {:ok, response} <- WebFinger.webfinger(resource, "JSON") do
35 _e -> send_resp(conn, 404, "Couldn't find user")
39 send_resp(conn, 404, "Unsupported format")
43 def webfinger(conn, _params) do
44 send_resp(conn, 400, "Bad Request")