set adapter opts in connection

This commit is contained in:
Alex S 2019-08-20 18:37:22 +03:00
parent 6f08e77269
commit cee945bead
2 changed files with 34 additions and 26 deletions

View File

@ -35,9 +35,33 @@ defmodule Pleroma.HTTP.Connection do
adapter_options = Pleroma.Config.get([:http, :adapter], []) adapter_options = Pleroma.Config.get([:http, :adapter], [])
proxy_url = Pleroma.Config.get([:http, :proxy_url], nil) proxy_url = Pleroma.Config.get([:http, :proxy_url], nil)
@options options =
|> Keyword.merge(adapter_options) @options
|> Keyword.merge(options) |> Keyword.merge(adapter_options)
|> Keyword.merge(proxy: proxy_url) |> Keyword.merge(options)
|> Keyword.merge(proxy: proxy_url)
pool = options[:pool]
url = options[:url]
if not is_nil(url) and not is_nil(pool) and Pleroma.Gun.Connections.alive?(pool) do
get_conn_for_gun(url, options, pool)
else
options
end
end
defp get_conn_for_gun(url, options, pool) do
case Pleroma.Gun.Connections.get_conn(url, options, pool) do
nil ->
options
conn ->
%{host: host, port: port} = URI.parse(url)
Keyword.put(options, :conn, conn)
|> Keyword.put(:close_conn, false)
|> Keyword.put(:original, "#{host}:#{port}")
end
end end
end end

View File

@ -34,11 +34,13 @@ defmodule Pleroma.HTTP do
adapter_gun? = Application.get_env(:tesla, :adapter) == Tesla.Adapter.Gun adapter_gun? = Application.get_env(:tesla, :adapter) == Tesla.Adapter.Gun
pool = options[:adapter][:pool]
options = options =
if adapter_gun? and not is_nil(pool) and Pleroma.Gun.Connections.alive?(pool) do if adapter_gun? do
get_conn_for_gun(url, options, pool) adapter_opts =
Keyword.get(options, :adapter, [])
|> Keyword.put(:url, url)
Keyword.put(options, :adapter, adapter_opts)
else else
options options
end end
@ -63,24 +65,6 @@ defmodule Pleroma.HTTP do
end end
end end
defp get_conn_for_gun(url, options, pool) do
case Pleroma.Gun.Connections.get_conn(url, options, pool) do
nil ->
options
conn ->
%{host: host, port: port} = URI.parse(url)
adapter_opts =
Keyword.get(options, :adapter, [])
|> Keyword.put(:conn, conn)
|> Keyword.put(:close_conn, false)
|> Keyword.put(:original, "#{host}:#{port}")
Keyword.put(options, :adapter, adapter_opts)
end
end
defp process_sni_options(options, nil), do: options defp process_sni_options(options, nil), do: options
defp process_sni_options(options, url) do defp process_sni_options(options, url) do