X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Freverse_proxy%2Fclient%2Ftesla.ex;h=36a0a2060959257a4e3e7a662e6a8beec271add2;hb=c0437d12440acb08f30a456fade657de735c19d8;hp=65785445d2a5021d7ee4d57062b64315c653bc18;hpb=3a2b2cb6f2d6ce39ae0d246649189c021c535992;p=akkoma
diff --git a/lib/pleroma/reverse_proxy/client/tesla.ex b/lib/pleroma/reverse_proxy/client/tesla.ex
index 65785445d..36a0a2060 100644
--- a/lib/pleroma/reverse_proxy/client/tesla.ex
+++ b/lib/pleroma/reverse_proxy/client/tesla.ex
@@ -1,10 +1,12 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ReverseProxy.Client.Tesla do
@behaviour Pleroma.ReverseProxy.Client
+ alias Pleroma.Gun.ConnectionPool
+
@type headers() :: [{String.t(), String.t()}]
@type status() :: pos_integer()
@@ -26,11 +28,13 @@ defmodule Pleroma.ReverseProxy.Client.Tesla do
url,
body,
headers,
- Keyword.put(opts, :adapter, opts)
+ opts
) do
if is_map(response.body) and method != :head do
{:ok, response.status, response.headers, response.body}
else
+ conn_pid = response.opts[:adapter][:conn]
+ ConnectionPool.release_conn(conn_pid)
{:ok, response.status, response.headers}
end
else
@@ -41,15 +45,8 @@ defmodule Pleroma.ReverseProxy.Client.Tesla do
@impl true
@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
- if opts[:old_conn], do: Tesla.Adapter.Gun.close(pid)
- # if there were redirects we need to checkout old conn
- conn = opts[:old_conn] || opts[:conn]
-
- if conn, do: :ok = Pleroma.Gun.ConnectionPool.release_conn(conn)
-
+ def stream_body(%{pid: pid, fin: true}) do
+ ConnectionPool.release_conn(pid)
:done
end
@@ -74,8 +71,7 @@ defmodule Pleroma.ReverseProxy.Client.Tesla do
@impl true
@spec close(map) :: :ok | no_return()
def close(%{pid: pid}) do
- adapter = check_adapter()
- adapter.close(pid)
+ ConnectionPool.release_conn(pid)
end
defp check_adapter do