15a84cf7361bd381c4d27f5160328aa7e5571325
[anni] / lib / pleroma / http / adapter_helper / hackney.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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   ]
10
11   @spec options(keyword(), URI.t()) :: keyword()
12   def options(connection_opts \\ [], %URI{} = uri) do
13     proxy = Pleroma.Config.get([:http, :proxy_url])
14
15     config_opts = Pleroma.Config.get([:http, :adapter], [])
16
17     @defaults
18     |> Keyword.merge(config_opts)
19     |> Keyword.merge(connection_opts)
20     |> add_scheme_opts(uri)
21     |> maybe_add_with_body()
22     |> Pleroma.HTTP.AdapterHelper.maybe_add_proxy(proxy)
23   end
24
25   defp add_scheme_opts(opts, _), do: opts
26
27   defp maybe_add_with_body(opts) do
28     if opts[:max_body] do
29       Keyword.put(opts, :with_body, true)
30     else
31       opts
32     end
33   end
34 end