Pleroma/lib/pleroma/http/adapter_helper/hackney.ex

37 lines
911 B
Elixir
Raw Normal View History

2020-03-03 16:53:44 +01:00
defmodule Pleroma.HTTP.AdapterHelper.Hackney do
@behaviour Pleroma.HTTP.AdapterHelper
2020-02-11 08:12:57 +01:00
@defaults [
follow_redirect: true,
force_redirect: true
2020-02-11 08:12:57 +01:00
]
@spec options(keyword(), URI.t()) :: keyword()
def options(connection_opts \\ [], %URI{} = uri) do
2020-03-13 07:37:57 +01:00
proxy = Pleroma.Config.get([:http, :proxy_url])
2020-02-11 08:12:57 +01:00
2020-03-06 19:24:19 +01:00
config_opts = Pleroma.Config.get([:http, :adapter], [])
2020-02-11 08:12:57 +01:00
@defaults
2020-03-06 19:24:19 +01:00
|> Keyword.merge(config_opts)
2020-02-11 08:12:57 +01:00
|> Keyword.merge(connection_opts)
|> add_scheme_opts(uri)
|> maybe_add_with_body()
2020-03-03 16:53:44 +01:00
|> Pleroma.HTTP.AdapterHelper.maybe_add_proxy(proxy)
2020-02-11 08:12:57 +01:00
end
2020-09-04 13:24:15 +02:00
defp add_scheme_opts(opts, %URI{scheme: "https"}) do
Keyword.put(opts, :ssl_options, versions: [:"tlsv1.2", :"tlsv1.1", :tlsv1])
end
defp add_scheme_opts(opts, _), do: opts
defp maybe_add_with_body(opts) do
if opts[:max_body] do
Keyword.put(opts, :with_body, true)
else
opts
end
end
2020-02-11 08:12:57 +01:00
end