# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.HTTP.Adapter do
+defmodule Pleroma.HTTP.AdapterHelper do
alias Pleroma.HTTP.Connection
@type proxy ::
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.HTTP.Adapter.Gun do
- @behaviour Pleroma.HTTP.Adapter
+defmodule Pleroma.HTTP.AdapterHelper.Gun do
+ @behaviour Pleroma.HTTP.AdapterHelper
- alias Pleroma.HTTP.Adapter
+ alias Pleroma.HTTP.AdapterHelper
require Logger
|> Keyword.merge(Pleroma.Config.get([:http, :adapter], []))
|> add_original(uri)
|> add_scheme_opts(uri)
- |> Adapter.maybe_add_proxy(Adapter.format_proxy(proxy))
+ |> AdapterHelper.maybe_add_proxy(AdapterHelper.format_proxy(proxy))
|> maybe_get_conn(uri, connection_opts)
end
-defmodule Pleroma.HTTP.Adapter.Hackney do
- @behaviour Pleroma.HTTP.Adapter
+defmodule Pleroma.HTTP.AdapterHelper.Hackney do
+ @behaviour Pleroma.HTTP.AdapterHelper
@defaults [
connect_timeout: 10_000,
|> Keyword.merge(Pleroma.Config.get([:http, :adapter], []))
|> Keyword.merge(connection_opts)
|> add_scheme_opts(uri)
- |> Pleroma.HTTP.Adapter.maybe_add_proxy(proxy)
+ |> Pleroma.HTTP.AdapterHelper.maybe_add_proxy(proxy)
end
defp add_scheme_opts(opts, %URI{scheme: "http"}), do: opts
require Logger
alias Pleroma.Config
- alias Pleroma.HTTP.Adapter
+ alias Pleroma.HTTP.AdapterHelper
@doc """
Merge default connection & adapter options with received ones.
defp adapter do
case Application.get_env(:tesla, :adapter) do
- Tesla.Adapter.Gun -> Adapter.Gun
- Tesla.Adapter.Hackney -> Adapter.Hackney
- _ -> Adapter
+ Tesla.Adapter.Gun -> AdapterHelper.Gun
+ Tesla.Adapter.Hackney -> AdapterHelper.Hackney
+ _ -> AdapterHelper
end
end
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.HTTP.Adapter.GunTest do
+defmodule Pleroma.HTTP.AdapterHelper.GunTest do
use ExUnit.Case, async: true
use Pleroma.Tests.Helpers
import ExUnit.CaptureLog
alias Pleroma.Config
alias Pleroma.Gun.Conn
- alias Pleroma.HTTP.Adapter.Gun
+ alias Pleroma.HTTP.AdapterHelper.Gun
alias Pleroma.Pool.Connections
setup_all do
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.HTTP.Adapter.HackneyTest do
+defmodule Pleroma.HTTP.AdapterHelper.HackneyTest do
use ExUnit.Case
use Pleroma.Tests.Helpers
alias Pleroma.Config
- alias Pleroma.HTTP.Adapter.Hackney
+ alias Pleroma.HTTP.AdapterHelper.Hackney
setup_all do
uri = URI.parse("http://domain.com")
--- /dev/null
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.HTTP.AdapterHelperTest do
+ use ExUnit.Case, async: true
+
+ alias Pleroma.HTTP.AdapterHelper
+
+ describe "format_proxy/1" do
+ test "with nil" do
+ assert AdapterHelper.format_proxy(nil) == nil
+ end
+
+ test "with string" do
+ assert AdapterHelper.format_proxy("127.0.0.1:8123") == {{127, 0, 0, 1}, 8123}
+ end
+
+ test "localhost with port" do
+ assert AdapterHelper.format_proxy("localhost:8123") == {'localhost', 8123}
+ end
+
+ test "tuple" do
+ assert AdapterHelper.format_proxy({:socks4, :localhost, 9050}) ==
+ {:socks4, 'localhost', 9050}
+ end
+ end
+end
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.HTTP.AdapterTest do
- use ExUnit.Case, async: true
-
- alias Pleroma.HTTP.Adapter
-
- describe "format_proxy/1" do
- test "with nil" do
- assert Adapter.format_proxy(nil) == nil
- end
-
- test "with string" do
- assert Adapter.format_proxy("127.0.0.1:8123") == {{127, 0, 0, 1}, 8123}
- end
-
- test "localhost with port" do
- assert Adapter.format_proxy("localhost:8123") == {'localhost', 8123}
- end
-
- test "tuple" do
- assert Adapter.format_proxy({:socks4, :localhost, 9050}) == {:socks4, 'localhost', 9050}
- end
- end
-end