Use runtime configuration for HTTP clients user-agent
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -5,28 +5,26 @@ defmodule Mobilizon.Service.HTTP.ActivityPub do
|
||||
|
||||
alias Mobilizon.Config
|
||||
|
||||
@adapter Application.get_env(:tesla, __MODULE__, [])[:adapter] || Tesla.Adapter.Hackney
|
||||
@default_opts [
|
||||
recv_timeout: 20_000
|
||||
]
|
||||
@user_agent Config.instance_user_agent()
|
||||
|
||||
def client(options \\ []) do
|
||||
headers = Keyword.get(options, :headers, [])
|
||||
adapter = Application.get_env(:tesla, __MODULE__, [])[:adapter] || Tesla.Adapter.Hackney
|
||||
opts = Keyword.merge(@default_opts, Keyword.get(options, :opts, []))
|
||||
|
||||
middleware = [
|
||||
{Tesla.Middleware.Headers,
|
||||
[{"User-Agent", @user_agent}, {"Accept", "application/activity+json"}] ++ headers},
|
||||
[{"User-Agent", Config.instance_user_agent()}, {"Accept", "application/activity+json"}] ++
|
||||
headers},
|
||||
Tesla.Middleware.FollowRedirects,
|
||||
{Tesla.Middleware.Timeout, timeout: 10_000},
|
||||
{Tesla.Middleware.JSON,
|
||||
decode_content_types: ["application/activity+json", "application/ld+json"]}
|
||||
]
|
||||
|
||||
adapter = {@adapter, opts}
|
||||
|
||||
Tesla.client(middleware, adapter)
|
||||
Tesla.client(middleware, {adapter, opts})
|
||||
end
|
||||
|
||||
def get(client, url) do
|
||||
|
||||
Reference in New Issue
Block a user