2020-03-03 08:53:44 -07:00
|
|
|
defmodule Pleroma.HTTP.AdapterHelper.Hackney do
|
|
|
|
@behaviour Pleroma.HTTP.AdapterHelper
|
2020-02-11 00:12:57 -07:00
|
|
|
|
|
|
|
@defaults [
|
|
|
|
connect_timeout: 10_000,
|
|
|
|
recv_timeout: 20_000,
|
|
|
|
follow_redirect: true,
|
|
|
|
force_redirect: true,
|
|
|
|
pool: :federation
|
|
|
|
]
|
|
|
|
|
|
|
|
@spec options(keyword(), URI.t()) :: keyword()
|
|
|
|
def options(connection_opts \\ [], %URI{} = uri) do
|
2020-03-13 00:37:57 -06:00
|
|
|
proxy = Pleroma.Config.get([:http, :proxy_url])
|
2020-02-11 00:12:57 -07:00
|
|
|
|
2020-03-06 11:24:19 -07:00
|
|
|
config_opts = Pleroma.Config.get([:http, :adapter], [])
|
|
|
|
|
2020-02-11 00:12:57 -07:00
|
|
|
@defaults
|
2020-03-06 11:24:19 -07:00
|
|
|
|> Keyword.merge(config_opts)
|
2020-02-11 00:12:57 -07:00
|
|
|
|> Keyword.merge(connection_opts)
|
|
|
|
|> add_scheme_opts(uri)
|
2020-03-03 08:53:44 -07:00
|
|
|
|> Pleroma.HTTP.AdapterHelper.maybe_add_proxy(proxy)
|
2020-02-11 00:12:57 -07:00
|
|
|
end
|
|
|
|
|
2020-09-07 06:47:43 -06:00
|
|
|
defp add_scheme_opts(opts, %URI{scheme: "https"}) do
|
|
|
|
Keyword.put(opts, :ssl_options, versions: [:"tlsv1.2", :"tlsv1.1", :tlsv1])
|
|
|
|
end
|
|
|
|
|
2020-05-30 04:59:04 -06:00
|
|
|
defp add_scheme_opts(opts, _), do: opts
|
2020-02-11 00:12:57 -07:00
|
|
|
|
2020-05-05 16:51:10 -06:00
|
|
|
@spec get_conn(URI.t(), keyword()) :: {:ok, keyword()}
|
|
|
|
def get_conn(_uri, opts), do: {:ok, opts}
|
2020-02-11 00:12:57 -07:00
|
|
|
end
|