@spec options(keyword(), URI.t()) :: keyword()
def options(incoming_opts \\ [], %URI{} = uri) do
proxy =
- Pleroma.Config.get([:http, :proxy_url], nil)
+ Pleroma.Config.get([:http, :proxy_url])
|> AdapterHelper.format_proxy()
config_opts = Pleroma.Config.get([:http, :adapter], [])
@spec options(keyword(), URI.t()) :: keyword()
def options(connection_opts \\ [], %URI{} = uri) do
- proxy = Pleroma.Config.get([:http, :proxy_url], nil)
+ proxy = Pleroma.Config.get([:http, :proxy_url])
config_opts = Pleroma.Config.get([:http, :adapter], [])
@defaults
|> pool_timeout()
|> Keyword.merge(opts)
- |> adapter().options(uri)
+ |> adapter_helper().options(uri)
end
defp pool_timeout(opts) do
{config_key, default} =
- if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Gun do
+ if adapter() == Tesla.Adapter.Gun do
{:pools, Config.get([:pools, :default, :timeout])}
else
{:hackney_pools, 10_000}
end
@spec after_request(keyword()) :: :ok
- def after_request(opts), do: adapter().after_request(opts)
+ def after_request(opts), do: adapter_helper().after_request(opts)
- defp adapter do
- case Application.get_env(:tesla, :adapter) do
+ defp adapter, do: Application.get_env(:tesla, :adapter)
+
+ defp adapter_helper do
+ case adapter() do
Tesla.Adapter.Gun -> AdapterHelper.Gun
Tesla.Adapter.Hackney -> AdapterHelper.Hackney
_ -> AdapterHelper
@impl true
def handle_info({:gun_down, _conn, _protocol, _reason, _killed}, state) do
- # don't flush messages here, because gun can reconnect
{:noreply, state}
end
end
def init(_) do
- children =
- [
- %{
- id: Pool.Connections,
- start:
- {Pool.Connections, :start_link, [{:gun_connections, Config.get([:connections_pool])}]}
- }
- ] ++ pools()
-
- Supervisor.init(children, strategy: :one_for_one)
+ conns_child = %{
+ id: Pool.Connections,
+ start:
+ {Pool.Connections, :start_link, [{:gun_connections, Config.get([:connections_pool])}]}
+ }
+
+ Supervisor.init([conns_child | pools()], strategy: :one_for_one)
end
defp pools do
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ReverseProxy.Client.Tesla do
+ @behaviour Pleroma.ReverseProxy.Client
+
@type headers() :: [{String.t(), String.t()}]
@type status() :: pos_integer()
- @behaviour Pleroma.ReverseProxy.Client
-
@spec request(atom(), String.t(), headers(), String.t(), keyword()) ::
{:ok, status(), headers}
| {:ok, status(), headers, map()}
def request(method, url, headers, body, opts \\ []) do
check_adapter()
- opts = Keyword.merge(opts, body_as: :chunks)
+ opts = Keyword.put(opts, :body_as, :chunks)
with {:ok, response} <-
Pleroma.HTTP.request(
end
@impl true
- @spec stream_body(map()) :: {:ok, binary(), map()} | {:error, atom() | String.t()} | :done
+ @spec stream_body(map()) ::
+ {:ok, binary(), map()} | {:error, atom() | String.t()} | :done | no_return()
def stream_body(%{pid: pid, opts: opts, fin: true}) do
# if connection was reused, but in tesla were redirects,
# tesla returns new opened connection, which must be closed manually
* `req_headers`, `resp_headers` additional headers.
- * `http`: options for [gun](https://github.com/ninenines/gun).
+ * `http`: options for [hackney](https://github.com/benoitc/hackney) or [gun](https://github.com/ninenines/gun).
"""
@default_options [pool: :media]