more clean up
This commit is contained in:
parent
39ed608b13
commit
98ed0d1c4b
@ -22,7 +22,7 @@ defmodule Pleroma.HTTP.AdapterHelper.Gun do
|
||||
@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], [])
|
||||
|
@ -11,7 +11,7 @@ defmodule Pleroma.HTTP.AdapterHelper.Hackney do
|
||||
|
||||
@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], [])
|
||||
|
||||
|
@ -30,12 +30,12 @@ defmodule Pleroma.HTTP.Connection do
|
||||
@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}
|
||||
@ -47,10 +47,12 @@ defmodule Pleroma.HTTP.Connection do
|
||||
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
|
||||
|
@ -39,7 +39,6 @@ defmodule Pleroma.Pool.Request do
|
||||
|
||||
@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
|
||||
|
||||
|
@ -13,16 +13,13 @@ defmodule Pleroma.Pool.Supervisor do
|
||||
end
|
||||
|
||||
def init(_) do
|
||||
children =
|
||||
[
|
||||
%{
|
||||
id: Pool.Connections,
|
||||
start:
|
||||
{Pool.Connections, :start_link, [{:gun_connections, Config.get([:connections_pool])}]}
|
||||
}
|
||||
] ++ pools()
|
||||
conns_child = %{
|
||||
id: Pool.Connections,
|
||||
start:
|
||||
{Pool.Connections, :start_link, [{:gun_connections, Config.get([:connections_pool])}]}
|
||||
}
|
||||
|
||||
Supervisor.init(children, strategy: :one_for_one)
|
||||
Supervisor.init([conns_child | pools()], strategy: :one_for_one)
|
||||
end
|
||||
|
||||
defp pools do
|
||||
|
@ -3,11 +3,11 @@
|
||||
# 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()}
|
||||
@ -18,7 +18,7 @@ defmodule Pleroma.ReverseProxy.Client.Tesla do
|
||||
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(
|
||||
@ -39,7 +39,8 @@ defmodule Pleroma.ReverseProxy.Client.Tesla do
|
||||
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
|
||||
|
@ -59,7 +59,7 @@ defmodule Pleroma.ReverseProxy do
|
||||
|
||||
* `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]
|
||||
|
Loading…
Reference in New Issue
Block a user