Ensure Gun is Gone
[akkoma] / lib / pleroma / reverse_proxy / client / wrapper.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.ReverseProxy.Client.Wrapper do
6 @moduledoc "Meta-client that calls the appropriate client from the config."
7 @behaviour Pleroma.ReverseProxy.Client
8
9 @impl true
10 def request(method, url, headers, body \\ "", opts \\ []) do
11 client().request(method, url, headers, body, opts)
12 end
13
14 @impl true
15 def stream_body(ref), do: client().stream_body(ref)
16
17 @impl true
18 def close(ref), do: client().close(ref)
19
20 defp client do
21 :tesla
22 |> Application.get_env(:adapter)
23 |> client()
24 end
25
26 defp client({Tesla.Adapter.Finch, _}), do: Pleroma.ReverseProxy.Client.Tesla
27 defp client(_), do: Pleroma.Config.get!(Pleroma.ReverseProxy.Client)
28 end