moving some logic to tesla adapter
- checking original inside gun adapter - flushing streams on max_body error
This commit is contained in:
parent
22d52f5691
commit
d6bebd4f9c
6 changed files with 6 additions and 34 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue