Fix webfinger not following redirections by using a custom dedicated Tesla client
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -12,18 +12,12 @@ defmodule Mobilizon.Federation.WebFinger do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
alias Mobilizon.Federation.WebFinger.XmlBuilder
|
||||
alias Mobilizon.Service.HTTP.WebfingerClient
|
||||
alias Mobilizon.Web.Endpoint
|
||||
alias Mobilizon.Web.Router.Helpers, as: Routes
|
||||
require Jason
|
||||
require Logger
|
||||
|
||||
@http_options [
|
||||
adapter: [
|
||||
follow_redirect: true,
|
||||
ssl: [{:versions, [:"tlsv1.2"]}]
|
||||
]
|
||||
]
|
||||
|
||||
def host_meta do
|
||||
base_url = Endpoint.url()
|
||||
|
||||
@@ -120,17 +114,9 @@ defmodule Mobilizon.Federation.WebFinger do
|
||||
Logger.debug(inspect(address))
|
||||
|
||||
with false <- is_nil(domain),
|
||||
{:ok, %{} = response} <-
|
||||
Tesla.get(
|
||||
address,
|
||||
headers: [
|
||||
{"accept", "application/json, application/activity+json, application/jrd+json"}
|
||||
],
|
||||
opts: @http_options
|
||||
),
|
||||
%{status: status, body: body} when status in 200..299 <- response,
|
||||
{:ok, doc} <- Jason.decode(body) do
|
||||
webfinger_from_json(doc)
|
||||
{:ok, %{body: body, status: code}} when code in 200..299 <-
|
||||
WebfingerClient.get(address) do
|
||||
webfinger_from_json(body)
|
||||
else
|
||||
e ->
|
||||
Logger.debug(fn -> "Couldn't finger #{actor}" end)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
defmodule Mobilizon.Service.HTTP.RichMediaPreviewClient do
|
||||
@moduledoc """
|
||||
Tesla HTTP Basic Client
|
||||
with JSON middleware
|
||||
Tesla HTTP Basic Client that fetches HTML to extract metadata preview
|
||||
"""
|
||||
|
||||
use Tesla
|
||||
|
||||
34
lib/service/http/webfinger_client.ex
Normal file
34
lib/service/http/webfinger_client.ex
Normal file
@@ -0,0 +1,34 @@
|
||||
defmodule Mobilizon.Service.HTTP.WebfingerClient do
|
||||
@moduledoc """
|
||||
Tesla HTTP Basic Client
|
||||
with JSON middleware
|
||||
"""
|
||||
|
||||
use Tesla
|
||||
alias Mobilizon.Config
|
||||
|
||||
@default_opts [
|
||||
recv_timeout: 20_000
|
||||
]
|
||||
|
||||
adapter(Tesla.Adapter.Hackney, @default_opts)
|
||||
|
||||
@user_agent Config.instance_user_agent()
|
||||
|
||||
plug(Tesla.Middleware.FollowRedirects)
|
||||
|
||||
plug(Tesla.Middleware.Timeout, timeout: 10_000)
|
||||
|
||||
plug(Tesla.Middleware.Headers, [
|
||||
{"User-Agent", @user_agent},
|
||||
{"Accept", "application/json, application/activity+json, application/jrd+json"}
|
||||
])
|
||||
|
||||
plug(Tesla.Middleware.JSON,
|
||||
decode_content_types: [
|
||||
"application/jrd+json",
|
||||
"application/json",
|
||||
"application/activity+json"
|
||||
]
|
||||
)
|
||||
end
|
||||
Reference in New Issue
Block a user