Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[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 force_redirect: true,
15 pool: :federation
16 ]
17 @adapter Application.get_env(:tesla, :adapter)
18
19 @doc """
20 Configure a client connection
21
22 # Returns
23
24 Tesla.Env.client
25 """
26 @spec new(Keyword.t()) :: Tesla.Env.client()
27 def new(opts \\ []) do
28 Tesla.client([], {@adapter, hackney_options(opts)})
29 end
30
31 # fetch Hackney options
32 #
33 def hackney_options(opts) do
34 options = Keyword.get(opts, :adapter, [])
35 adapter_options = Pleroma.Config.get([:http, :adapter], [])
36 proxy_url = Pleroma.Config.get([:http, :proxy_url], nil)
37
38 @hackney_options
39 |> Keyword.merge(adapter_options)
40 |> Keyword.merge(options)
41 |> Keyword.merge(proxy: proxy_url)
42 end
43 end