little refactor
This commit is contained in:
parent
56ff02f2ef
commit
c93c3096d5
@ -11,6 +11,10 @@ defmodule Pleroma.Gun do
|
|||||||
@callback await(pid(), reference()) :: {:response, :fin, 200, []}
|
@callback await(pid(), reference()) :: {:response, :fin, 200, []}
|
||||||
@callback set_owner(pid(), pid()) :: :ok
|
@callback set_owner(pid(), pid()) :: :ok
|
||||||
|
|
||||||
|
@api Pleroma.Config.get([Pleroma.Gun], Pleroma.Gun.API)
|
||||||
|
|
||||||
|
defp api, do: @api
|
||||||
|
|
||||||
def open(host, port, opts), do: api().open(host, port, opts)
|
def open(host, port, opts), do: api().open(host, port, opts)
|
||||||
|
|
||||||
def info(pid), do: api().info(pid)
|
def info(pid), do: api().info(pid)
|
||||||
@ -24,6 +28,4 @@ defmodule Pleroma.Gun do
|
|||||||
def await(pid, ref), do: api().await(pid, ref)
|
def await(pid, ref), do: api().await(pid, ref)
|
||||||
|
|
||||||
def set_owner(pid, owner), do: api().set_owner(pid, owner)
|
def set_owner(pid, owner), do: api().set_owner(pid, owner)
|
||||||
|
|
||||||
defp api, do: Pleroma.Config.get([Pleroma.Gun], Pleroma.Gun.API)
|
|
||||||
end
|
end
|
||||||
|
@ -5,10 +5,9 @@
|
|||||||
defmodule Pleroma.HTTP.AdapterHelper.Gun do
|
defmodule Pleroma.HTTP.AdapterHelper.Gun do
|
||||||
@behaviour Pleroma.HTTP.AdapterHelper
|
@behaviour Pleroma.HTTP.AdapterHelper
|
||||||
|
|
||||||
alias Pleroma.HTTP.AdapterHelper
|
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
alias Pleroma.HTTP.AdapterHelper
|
||||||
alias Pleroma.Pool.Connections
|
alias Pleroma.Pool.Connections
|
||||||
|
|
||||||
@defaults [
|
@defaults [
|
||||||
@ -22,20 +21,23 @@ defmodule Pleroma.HTTP.AdapterHelper.Gun do
|
|||||||
|
|
||||||
@spec options(keyword(), URI.t()) :: keyword()
|
@spec options(keyword(), URI.t()) :: keyword()
|
||||||
def options(connection_opts \\ [], %URI{} = uri) do
|
def options(connection_opts \\ [], %URI{} = uri) do
|
||||||
proxy = Pleroma.Config.get([:http, :proxy_url], nil)
|
formatted_proxy =
|
||||||
|
Pleroma.Config.get([:http, :proxy_url], nil)
|
||||||
|
|> AdapterHelper.format_proxy()
|
||||||
|
|
||||||
|
config_opts = Pleroma.Config.get([:http, :adapter], [])
|
||||||
|
|
||||||
@defaults
|
@defaults
|
||||||
|> Keyword.merge(Pleroma.Config.get([:http, :adapter], []))
|
|> Keyword.merge(config_opts)
|
||||||
|> add_scheme_opts(uri)
|
|> add_scheme_opts(uri)
|
||||||
|> AdapterHelper.maybe_add_proxy(AdapterHelper.format_proxy(proxy))
|
|> AdapterHelper.maybe_add_proxy(formatted_proxy)
|
||||||
|> maybe_get_conn(uri, connection_opts)
|
|> maybe_get_conn(uri, connection_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec after_request(keyword()) :: :ok
|
@spec after_request(keyword()) :: :ok
|
||||||
def after_request(opts) do
|
def after_request(opts) do
|
||||||
with conn when not is_nil(conn) <- opts[:conn],
|
if opts[:conn] && opts[:body_as] != :chunks do
|
||||||
body_as when body_as != :chunks <- opts[:body_as] do
|
Connections.checkout(opts[:conn], self(), :gun_connections)
|
||||||
Connections.checkout(conn, self(), :gun_connections)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
|
Loading…
Reference in New Issue
Block a user