Resolve merge conflicts
[akkoma] / lib / pleroma / http / connection.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.HTTP.Connection do
6 @moduledoc """
7 Connection for http-requests.
8 """
9
10 @hackney_options [
11 connect_timeout: 10_000,
12 recv_timeout: 20_000,
13 follow_redirect: true,
14 pool: :federation
15 ]
16 @adapter Application.get_env(:tesla, :adapter)
17
18 @doc """
19 Configure a client connection
20
21 # Returns
22
23 Tesla.Env.client
24 """
25 @spec new(Keyword.t()) :: Tesla.Env.client()
26 def new(opts \\ []) do
27 Tesla.client([], {@adapter, hackney_options(opts)})
28 end
29
30 # fetch Hackney options
31 #
32 def hackney_options(opts) do
33 options = Keyword.get(opts, :adapter, [])
34 adapter_options = Pleroma.Config.get([:http, :adapter], [])
35 proxy_url = Pleroma.Config.get([:http, :proxy_url], nil)
36
37 @hackney_options
38 |> Keyword.merge(adapter_options)
39 |> Keyword.merge(options)
40 |> Keyword.merge(proxy: proxy_url)
41 end
42 end