Merge branch 'bugfix/apc2s_upload_activity' into 'develop'
[akkoma] / lib / pleroma / reverse_proxy / client / tesla.ex
index 498a905e1f674590e9634395ad719ec5fd842109..e81ea8bde135be2045ce88b7ad292a7f6780a231 100644 (file)
@@ -1,13 +1,13 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.ReverseProxy.Client.Tesla do
+  @behaviour Pleroma.ReverseProxy.Client
+
   @type headers() :: [{String.t(), String.t()}]
   @type status() :: pos_integer()
 
-  @behaviour Pleroma.ReverseProxy.Client
-
   @spec request(atom(), String.t(), headers(), String.t(), keyword()) ::
           {:ok, status(), headers}
           | {:ok, status(), headers, map()}
@@ -18,8 +18,9 @@ defmodule Pleroma.ReverseProxy.Client.Tesla do
   def request(method, url, headers, body, opts \\ []) do
     check_adapter()
 
-    with opts <- Keyword.merge(opts, body_as: :chunks, mode: :passive),
-         {:ok, response} <-
+    opts = Keyword.put(opts, :body_as, :chunks)
+
+    with {:ok, response} <-
            Pleroma.HTTP.request(
              method,
              url,
@@ -38,9 +39,11 @@ defmodule Pleroma.ReverseProxy.Client.Tesla do
   end
 
   @impl true
-  @spec stream_body(map()) :: {:ok, binary(), map()} | {:error, atom() | String.t()} | :done
+  @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 sended and there were redirects, we need to close new conn - pid manually
+    # 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]