adapter options unification
[akkoma] / lib / pleroma / http / adapter_helper / hackney.ex
1 defmodule Pleroma.HTTP.AdapterHelper.Hackney do
2 @behaviour Pleroma.HTTP.AdapterHelper
3
4 @defaults [
5 follow_redirect: true,
6 force_redirect: true
7 ]
8
9 @spec options(keyword(), URI.t()) :: keyword()
10 def options(connection_opts \\ [], %URI{} = uri) do
11 proxy = Pleroma.Config.get([:http, :proxy_url])
12
13 config_opts = Pleroma.Config.get([:http, :adapter], [])
14
15 @defaults
16 |> Keyword.merge(config_opts)
17 |> Keyword.merge(connection_opts)
18 |> add_scheme_opts(uri)
19 |> maybe_add_with_body()
20 |> Pleroma.HTTP.AdapterHelper.maybe_add_proxy(proxy)
21 end
22
23 defp add_scheme_opts(opts, %URI{scheme: "https"}) do
24 Keyword.put(opts, :ssl_options, versions: [:"tlsv1.2", :"tlsv1.1", :tlsv1])
25 end
26
27 defp add_scheme_opts(opts, _), do: opts
28
29 defp maybe_add_with_body(opts) do
30 if opts[:max_body] do
31 Keyword.put(opts, :with_body, true)
32 else
33 opts
34 end
35 end
36 end