Merge branch 'develop' into gun
[akkoma] / lib / pleroma / http / adapter_helper / hackney.ex
1 defmodule Pleroma.HTTP.AdapterHelper.Hackney do
2 @behaviour Pleroma.HTTP.AdapterHelper
3
4 @defaults [
5 connect_timeout: 10_000,
6 recv_timeout: 20_000,
7 follow_redirect: true,
8 force_redirect: true,
9 pool: :federation
10 ]
11
12 @spec options(keyword(), URI.t()) :: keyword()
13 def options(connection_opts \\ [], %URI{} = uri) do
14 proxy = Pleroma.Config.get([:http, :proxy_url], nil)
15
16 config_opts = Pleroma.Config.get([:http, :adapter], [])
17
18 @defaults
19 |> Keyword.merge(config_opts)
20 |> Keyword.merge(connection_opts)
21 |> add_scheme_opts(uri)
22 |> Pleroma.HTTP.AdapterHelper.maybe_add_proxy(proxy)
23 end
24
25 defp add_scheme_opts(opts, %URI{scheme: "http"}), do: opts
26
27 defp add_scheme_opts(opts, %URI{scheme: "https", host: host}) do
28 ssl_opts = [
29 ssl_options: [
30 # Workaround for remote server certificate chain issues
31 partial_chain: &:hackney_connect.partial_chain/1,
32
33 # We don't support TLS v1.3 yet
34 versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"],
35 server_name_indication: to_charlist(host)
36 ]
37 ]
38
39 Keyword.merge(opts, ssl_opts)
40 end
41
42 def after_request(_), do: :ok
43 end