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