adapter renaming to adapter_helper
This commit is contained in:
parent
8854770fc4
commit
f98ee730f0
@ -2,7 +2,7 @@
|
||||
# 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 ::
|
@ -2,10 +2,10 @@
|
||||
# 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
|
||||
|
||||
@ -28,7 +28,7 @@ def options(connection_opts \\ [], %URI{} = uri) do
|
||||
|> 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
|
||||
|
@ -1,5 +1,5 @@
|
||||
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,
|
||||
@ -17,7 +17,7 @@ def options(connection_opts \\ [], %URI{} = uri) do
|
||||
|> 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
|
@ -18,7 +18,7 @@ defmodule Pleroma.HTTP.Connection do
|
||||
require Logger
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.HTTP.Adapter
|
||||
alias Pleroma.HTTP.AdapterHelper
|
||||
|
||||
@doc """
|
||||
Merge default connection & adapter options with received ones.
|
||||
@ -50,9 +50,9 @@ def after_request(opts), do: adapter().after_request(opts)
|
||||
|
||||
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
|
||||
|
||||
|
@ -2,13 +2,13 @@
|
||||
# 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
|
@ -2,12 +2,12 @@
|
||||
# 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")
|
28
test/http/adapter_helper_test.exs
Normal file
28
test/http/adapter_helper_test.exs
Normal file
@ -0,0 +1,28 @@
|
||||
# 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
|
@ -1,27 +0,0 @@
|
||||
# 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
|
Loading…
Reference in New Issue
Block a user