moving some logic to tesla adapter

- checking original inside gun adapter
- flushing streams on max_body error
This commit is contained in:
Alexander Strizhakov 2020-03-04 18:13:24 +03:00
commit d6bebd4f9c
No known key found for this signature in database
GPG key ID: 022896A53AEF1381
6 changed files with 6 additions and 34 deletions

View file

@ -26,7 +26,6 @@ defmodule Pleroma.HTTP.AdapterHelper.Gun do
@defaults
|> Keyword.merge(Pleroma.Config.get([:http, :adapter], []))
|> add_original(uri)
|> add_scheme_opts(uri)
|> AdapterHelper.maybe_add_proxy(AdapterHelper.format_proxy(proxy))
|> maybe_get_conn(uri, connection_opts)
@ -42,17 +41,12 @@ defmodule Pleroma.HTTP.AdapterHelper.Gun do
:ok
end
defp add_original(opts, %URI{host: host, port: port}) do
formatted_host = format_host(host)
Keyword.put(opts, :original, "#{formatted_host}:#{port}")
end
defp add_scheme_opts(opts, %URI{scheme: "http"}), do: opts
defp add_scheme_opts(opts, %URI{scheme: "https", host: host, port: port}) do
defp add_scheme_opts(opts, %URI{scheme: "https", host: host}) do
adapter_opts = [
certificates_verification: true,
transport: :tls,
tls_opts: [
verify: :verify_peer,
cacertfile: CAStore.file_path(),
@ -63,13 +57,6 @@ defmodule Pleroma.HTTP.AdapterHelper.Gun do
]
]
adapter_opts =
if port != 443 do
Keyword.put(adapter_opts, :transport, :tls)
else
adapter_opts
end
Keyword.merge(opts, adapter_opts)
end

View file

@ -28,12 +28,7 @@ defmodule Pleroma.Pool.Request do
end
@impl true
def handle_info({:gun_data, _conn, stream, _, _}, state) do
# in some cases if we reuse conn and got {:error, :body_too_large}
# gun continues to send messages to this process,
# so we flush messages for this request
:ok = :gun.flush(stream)
def handle_info({:gun_data, _conn, _stream, _, _}, state) do
{:noreply, state}
end
@ -49,8 +44,7 @@ defmodule Pleroma.Pool.Request do
end
@impl true
def handle_info({:gun_error, _conn, stream, _error}, state) do
:ok = :gun.flush(stream)
def handle_info({:gun_error, _conn, _stream, _error}, state) do
{:noreply, state}
end