moving some logic to tesla adapter
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Wed, 4 Mar 2020 15:13:24 +0000 (18:13 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Wed, 4 Mar 2020 15:13:24 +0000 (18:13 +0300)
- checking original inside gun adapter
- flushing streams on max_body error

lib/pleroma/http/adapter_helper/gun.ex
lib/pleroma/pool/request.ex
mix.exs
mix.lock
test/http/adapter_helper/gun_test.exs
test/http/connection_test.exs

index b3298ec7fbf33dbe56a0a7917ad872ebdf3ed6e4..5d5870d90200f5cbd5d48b4934a89c9802e0d170 100644 (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
 
index cce30959950b95db90be2aa367ef61846301dcc4..0f271b3d052b57bc23e3e2c47122ac617d834473 100644 (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
 
diff --git a/mix.exs b/mix.exs
index 5c1d892081680461a1accfd9553f4225b16235f3..43e7e6f63d960bbdc5cc04c71961ad38913e1d2b 100644 (file)
--- a/mix.exs
+++ b/mix.exs
@@ -122,7 +122,7 @@ defmodule Pleroma.Mixfile do
       # {:tesla, "~> 1.3", override: true},
       {:tesla,
        git: "https://git.pleroma.social/pleroma/elixir-libraries/tesla.git",
-       ref: "922cc3db13b421763edbea76246b8ea61c38c6fa",
+       ref: "67436cf003d40370e944462649193706bb22ca35",
        override: true},
       {:castore, "~> 0.1"},
       {:cowlib, "~> 2.8", override: true},
index 255b4888b923cc4b6b1591b6e9f71d966f09666a..b5daf50dc656128e5a3380ada643545ab9347901 100644 (file)
--- a/mix.lock
+++ b/mix.lock
   "swoosh": {:hex, :swoosh, "0.23.5", "bfd9404bbf5069b1be2ffd317923ce57e58b332e25dbca2a35dedd7820dfee5a", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm", "e3928e1d2889a308aaf3e42755809ac21cffd77cb58eef01cbfdab4ce2fd1e21"},
   "syslog": {:hex, :syslog, "1.0.6", "995970c9aa7feb380ac493302138e308d6e04fd57da95b439a6df5bb3bf75076", [:rebar3], [], "hexpm", "769ddfabd0d2a16f3f9c17eb7509951e0ca4f68363fb26f2ee51a8ec4a49881a"},
   "telemetry": {:hex, :telemetry, "0.4.1", "ae2718484892448a24470e6aa341bc847c3277bfb8d4e9289f7474d752c09c7f", [:rebar3], [], "hexpm", "4738382e36a0a9a2b6e25d67c960e40e1a2c95560b9f936d8e29de8cd858480f"},
-  "tesla": {:git, "https://git.pleroma.social/pleroma/elixir-libraries/tesla.git", "922cc3db13b421763edbea76246b8ea61c38c6fa", [ref: "922cc3db13b421763edbea76246b8ea61c38c6fa"]},
+  "tesla": {:git, "https://git.pleroma.social/pleroma/elixir-libraries/tesla.git", "67436cf003d40370e944462649193706bb22ca35", [ref: "67436cf003d40370e944462649193706bb22ca35"]},
   "timex": {:hex, :timex, "3.6.1", "efdf56d0e67a6b956cc57774353b0329c8ab7726766a11547e529357ffdc1d56", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5 or ~> 1.0.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "f354efb2400dd7a80fd9eb6c8419068c4f632da4ac47f3d8822d6e33f08bc852"},
   "trailing_format_plug": {:hex, :trailing_format_plug, "0.0.7", "64b877f912cf7273bed03379936df39894149e35137ac9509117e59866e10e45", [:mix], [{:plug, "> 0.12.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "bd4fde4c15f3e993a999e019d64347489b91b7a9096af68b2bdadd192afa693f"},
   "tzdata": {:hex, :tzdata, "0.5.22", "f2ba9105117ee0360eae2eca389783ef7db36d533899b2e84559404dbc77ebb8", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "cd66c8a1e6a9e121d1f538b01bef459334bb4029a1ffb4eeeb5e4eae0337e7b6"},
   "web_push_encryption": {:hex, :web_push_encryption, "0.2.3", "a0ceab85a805a30852f143d22d71c434046fbdbafbc7292e7887cec500826a80", [:mix], [{:httpoison, "~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:poison, "~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm", "9315c8f37c108835cf3f8e9157d7a9b8f420a34f402d1b1620a31aed5b93ecdf"},
   "websocket_client": {:git, "https://github.com/jeremyong/websocket_client.git", "9a6f65d05ebf2725d62fb19262b21f1805a59fbf", []},
 }
-
index 66ca416d960b619c0666312f0e2c4dc5f8cc251c..c1bf909a641ddbaed3add31dc101a97d5e83e15e 100644 (file)
@@ -35,8 +35,6 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do
                {&:ssl_verify_hostname.verify_fun/3, [check_hostname: 'example.com']}
 
       assert File.exists?(tls_opts[:cacertfile])
-
-      assert opts[:original] == "example.com:443"
     end
 
     test "https ipv4 with default port" do
@@ -46,8 +44,6 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do
 
       assert opts[:tls_opts][:verify_fun] ==
                {&:ssl_verify_hostname.verify_fun/3, [check_hostname: '127.0.0.1']}
-
-      assert opts[:original] == "127.0.0.1:443"
     end
 
     test "https ipv6 with default port" do
@@ -58,8 +54,6 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do
       assert opts[:tls_opts][:verify_fun] ==
                {&:ssl_verify_hostname.verify_fun/3,
                 [check_hostname: '2a03:2880:f10c:83:face:b00c:0:25de']}
-
-      assert opts[:original] == "2a03:2880:f10c:83:face:b00c:0:25de:443"
     end
 
     test "https url with non standart port" do
@@ -129,7 +123,6 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do
       assert tls_opts[:depth] == 20
       assert tls_opts[:reuse_sessions] == false
 
-      assert opts[:original] == "some-domain.com:443"
       assert opts[:close_conn] == false
       assert is_pid(opts[:conn])
     end
index 5c1ecda0be22906d4eab61d0a9b925119172c6db..d4db3798c716b80eb46b6fae06780b0c6b862fe2 100644 (file)
@@ -134,7 +134,6 @@ defmodule Pleroma.HTTP.ConnectionTest do
       assert tls_opts[:depth] == 20
       assert tls_opts[:reuse_sessions] == false
 
-      assert opts[:original] == "some-domain.com:443"
       assert opts[:close_conn] == false
       assert is_pid(opts[:conn])
     end