projects
/
akkoma
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
23f407b
)
refactoring for gun api modules
author
Alexander Strizhakov
<alex.strizhakov@gmail.com>
Tue, 3 Mar 2020 16:24:14 +0000
(19:24 +0300)
committer
Alexander Strizhakov
<alex.strizhakov@gmail.com>
Tue, 3 Mar 2020 16:24:14 +0000
(19:24 +0300)
12 files changed:
config/test.exs
patch
|
blob
|
history
lib/pleroma/gun/api.ex
patch
|
blob
|
history
lib/pleroma/gun/conn.ex
patch
|
blob
|
history
lib/pleroma/gun/gun.ex
patch
|
blob
|
history
lib/pleroma/pool/connections.ex
patch
|
blob
|
history
test/http/adapter_helper/gun_test.exs
patch
|
blob
|
history
test/http/connection_test.exs
patch
|
blob
|
history
test/http_test.exs
patch
|
blob
|
history
test/pool/connections_test.exs
patch
|
blob
|
history
test/reverse_proxy/client/tesla_test.exs
patch
|
blob
|
history
test/reverse_proxy/reverse_proxy_test.exs
patch
|
blob
|
history
test/support/gun_mock.ex
[moved from
lib/pleroma/gun/api/mock.ex
with 79% similarity]
patch
|
blob
|
history
diff --git
a/config/test.exs
b/config/test.exs
index 7cc669c1941b18392e69c9a631038a0ce5235619..bce9dd4aa839a8478bc352f0bf3a9e567d1dc818 100644
(file)
--- a/
config/test.exs
+++ b/
config/test.exs
@@
-90,7
+90,7
@@
config :pleroma, Pleroma.ReverseProxy.Client, Pleroma.ReverseProxy.ClientMock
config :pleroma, :modules, runtime_dir: "test/fixtures/modules"
config :pleroma, :modules, runtime_dir: "test/fixtures/modules"
-config :pleroma, Pleroma.Gun
.API, Pleroma.Gun.API.
Mock
+config :pleroma, Pleroma.Gun
, Pleroma.Gun
Mock
config :pleroma, Pleroma.Emails.NewUsersDigestEmail, enabled: true
config :pleroma, Pleroma.Emails.NewUsersDigestEmail, enabled: true
diff --git
a/lib/pleroma/gun/api.ex
b/lib/pleroma/gun/api.ex
index f79c9f4434c69823509bf8d79122090c8da4493b..76aac5874a3dff3d04f477af12f44ae9dfb3186a 100644
(file)
--- a/
lib/pleroma/gun/api.ex
+++ b/
lib/pleroma/gun/api.ex
@@
-3,27
+3,43
@@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Gun.API do
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Gun.API do
- @callback open(charlist(), pos_integer(), map()) :: {:ok, pid()}
- @callback info(pid()) :: map()
- @callback close(pid()) :: :ok
- @callback await_up(pid, pos_integer()) :: {:ok, atom()} | {:error, atom()}
- @callback connect(pid(), map()) :: reference()
- @callback await(pid(), reference()) :: {:response, :fin, 200, []}
- @callback set_owner(pid(), pid()) :: :ok
+ @behaviour Pleroma.Gun
- def open(host, port, opts), do: api().open(host, port, opts)
+ alias Pleroma.Gun
- def info(pid), do: api().info(pid)
+ @gun_keys [
+ :connect_timeout,
+ :http_opts,
+ :http2_opts,
+ :protocols,
+ :retry,
+ :retry_timeout,
+ :trace,
+ :transport,
+ :tls_opts,
+ :tcp_opts,
+ :socks_opts,
+ :ws_opts
+ ]
- def close(pid), do: api().close(pid)
+ @impl Gun
+ def open(host, port, opts \\ %{}), do: :gun.open(host, port, Map.take(opts, @gun_keys))
- def await_up(pid, timeout \\ 5_000), do: api().await_up(pid, timeout)
+ @impl Gun
+ defdelegate info(pid), to: :gun
- def connect(pid, opts), do: api().connect(pid, opts)
+ @impl Gun
+ defdelegate close(pid), to: :gun
- def await(pid, ref), do: api().await(pid, ref)
+ @impl Gun
+ defdelegate await_up(pid, timeout \\ 5_000), to: :gun
- def set_owner(pid, owner), do: api().set_owner(pid, owner)
+ @impl Gun
+ defdelegate connect(pid, opts), to: :gun
- defp api, do: Pleroma.Config.get([Pleroma.Gun.API], Pleroma.Gun)
+ @impl Gun
+ defdelegate await(pid, ref), to: :gun
+
+ @impl Gun
+ defdelegate set_owner(pid, owner), to: :gun
end
end
diff --git
a/lib/pleroma/gun/conn.ex
b/lib/pleroma/gun/conn.ex
index d73bec3605e8cae262d1922f620e4b87ea5fe74a..31971869049a0981da7fb274b0b87922774f06dc 100644
(file)
--- a/
lib/pleroma/gun/conn.ex
+++ b/
lib/pleroma/gun/conn.ex
@@
-6,7
+6,7
@@
defmodule Pleroma.Gun.Conn do
@moduledoc """
Struct for gun connection data
"""
@moduledoc """
Struct for gun connection data
"""
- alias Pleroma.Gun
.API
+ alias Pleroma.Gun
alias Pleroma.Pool.Connections
require Logger
alias Pleroma.Pool.Connections
require Logger
@@
-65,7
+65,7
@@
defmodule Pleroma.Gun.Conn do
last_reference: :os.system_time(:second)
}
last_reference: :os.system_time(:second)
}
- :ok =
API
.set_owner(conn_pid, Process.whereis(name))
+ :ok =
Gun
.set_owner(conn_pid, Process.whereis(name))
Connections.add_conn(name, key, conn)
end
end
Connections.add_conn(name, key, conn)
end
end
@@
-77,10
+77,10
@@
defmodule Pleroma.Gun.Conn do
|> add_http2_opts(uri.scheme, Map.get(opts, :tls_opts, []))
with open_opts <- Map.delete(opts, :tls_opts),
|> add_http2_opts(uri.scheme, Map.get(opts, :tls_opts, []))
with open_opts <- Map.delete(opts, :tls_opts),
- {:ok, conn} <-
API
.open(proxy_host, proxy_port, open_opts),
- {:ok, _} <-
API
.await_up(conn, opts[:await_up_timeout]),
- stream <-
API
.connect(conn, connect_opts),
- {:response, :fin, 200, _} <-
API
.await(conn, stream) do
+ {:ok, conn} <-
Gun
.open(proxy_host, proxy_port, open_opts),
+ {:ok, _} <-
Gun
.await_up(conn, opts[:await_up_timeout]),
+ stream <-
Gun
.connect(conn, connect_opts),
+ {:response, :fin, 200, _} <-
Gun
.await(conn, stream) do
conn
else
error ->
conn
else
error ->
@@
-115,8
+115,8
@@
defmodule Pleroma.Gun.Conn do
|> Map.put(:protocols, [:socks])
|> Map.put(:socks_opts, socks_opts)
|> Map.put(:protocols, [:socks])
|> Map.put(:socks_opts, socks_opts)
- with {:ok, conn} <-
API
.open(proxy_host, proxy_port, opts),
- {:ok, _} <-
API
.await_up(conn, opts[:await_up_timeout]) do
+ with {:ok, conn} <-
Gun
.open(proxy_host, proxy_port, opts),
+ {:ok, _} <-
Gun
.await_up(conn, opts[:await_up_timeout]) do
conn
else
error ->
conn
else
error ->
@@
-133,8
+133,8
@@
defmodule Pleroma.Gun.Conn do
defp do_open(%URI{host: host, port: port} = uri, opts) do
host = Pleroma.HTTP.Connection.parse_host(host)
defp do_open(%URI{host: host, port: port} = uri, opts) do
host = Pleroma.HTTP.Connection.parse_host(host)
- with {:ok, conn} <-
API
.open(host, port, opts),
- {:ok, _} <-
API
.await_up(conn, opts[:await_up_timeout]) do
+ with {:ok, conn} <-
Gun
.open(host, port, opts),
+ {:ok, _} <-
Gun
.await_up(conn, opts[:await_up_timeout]) do
conn
else
error ->
conn
else
error ->
@@
-164,7
+164,7
@@
defmodule Pleroma.Gun.Conn do
with [{close_key, least_used} | _conns] <-
Connections.get_unused_conns(name),
with [{close_key, least_used} | _conns] <-
Connections.get_unused_conns(name),
- :ok <-
Pleroma.Gun.API
.close(least_used.conn) do
+ :ok <-
Gun
.close(least_used.conn) do
Connections.remove_conn(name, close_key)
do_open(uri, opts)
Connections.remove_conn(name, close_key)
do_open(uri, opts)
diff --git
a/lib/pleroma/gun/gun.ex
b/lib/pleroma/gun/gun.ex
index da82983b1eed79db5c31f163956b4365e9e4571a..35390bb11ee845aa35c6b8faa5dcd33131270d63 100644
(file)
--- a/
lib/pleroma/gun/gun.ex
+++ b/
lib/pleroma/gun/gun.ex
@@
-3,46
+3,27
@@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Gun do
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Gun do
- @behaviour Pleroma.Gun.API
+ @callback open(charlist(), pos_integer(), map()) :: {:ok, pid()}
+ @callback info(pid()) :: map()
+ @callback close(pid()) :: :ok
+ @callback await_up(pid, pos_integer()) :: {:ok, atom()} | {:error, atom()}
+ @callback connect(pid(), map()) :: reference()
+ @callback await(pid(), reference()) :: {:response, :fin, 200, []}
+ @callback set_owner(pid(), pid()) :: :ok
- alias Pleroma.Gun.API
+ def open(host, port, opts), do: api().open(host, port, opts)
- @gun_keys [
- :connect_timeout,
- :http_opts,
- :http2_opts,
- :protocols,
- :retry,
- :retry_timeout,
- :trace,
- :transport,
- :tls_opts,
- :tcp_opts,
- :socks_opts,
- :ws_opts
- ]
+ def info(pid), do: api().info(pid)
- @impl API
- def open(host, port, opts \\ %{}), do: :gun.open(host, port, Map.take(opts, @gun_keys))
+ def close(pid), do: api().close(pid)
- @impl API
- defdelegate info(pid), to: :gun
+ def await_up(pid, timeout \\ 5_000), do: api().await_up(pid, timeout)
- @impl API
- defdelegate close(pid), to: :gun
+ def connect(pid, opts), do: api().connect(pid, opts)
- @impl API
- defdelegate await_up(pid, timeout \\ 5_000), to: :gun
+ def await(pid, ref), do: api().await(pid, ref)
- @impl API
- defdelegate connect(pid, opts), to: :gun
+ def set_owner(pid, owner), do: api().set_owner(pid, owner)
- @impl API
- defdelegate await(pid, ref), to: :gun
-
- @spec flush(pid() | reference()) :: :ok
- defdelegate flush(pid), to: :gun
-
- @impl API
- defdelegate set_owner(pid, owner), to: :gun
+ defp api, do: Pleroma.Config.get([Pleroma.Gun], Pleroma.Gun.API)
end
end
diff --git
a/lib/pleroma/pool/connections.ex
b/lib/pleroma/pool/connections.ex
index 0f7a1bfd820f60359fbfcbf0ddb99db1b7f890cd..92179fbfc1e968ee788f5bab0fedadbdcfbd6cfa 100644
(file)
--- a/
lib/pleroma/pool/connections.ex
+++ b/
lib/pleroma/pool/connections.ex
@@
-19,7
+19,7
@@
defmodule Pleroma.Pool.Connections do
defstruct conns: %{}, opts: []
defstruct conns: %{}, opts: []
- alias Pleroma.Gun
.API
+ alias Pleroma.Gun
@spec start_link({atom(), keyword()}) :: {:ok, pid()}
def start_link({name, opts}) do
@spec start_link({atom(), keyword()}) :: {:ok, pid()}
def start_link({name, opts}) do
@@
-209,7
+209,7
@@
defmodule Pleroma.Pool.Connections do
nil ->
Logger.debug(":gun_up message for conn which is not found in state")
nil ->
Logger.debug(":gun_up message for conn which is not found in state")
- :ok =
API
.close(conn_pid)
+ :ok =
Gun
.close(conn_pid)
state
end
state
end
@@
-226,7
+226,7
@@
defmodule Pleroma.Pool.Connections do
{true, key} <- {Process.alive?(conn_pid), key} do
if conn.retries == retries do
Logger.debug("closing conn if retries is eq #{inspect(conn_pid)}")
{true, key} <- {Process.alive?(conn_pid), key} do
if conn.retries == retries do
Logger.debug("closing conn if retries is eq #{inspect(conn_pid)}")
- :ok =
API
.close(conn.conn)
+ :ok =
Gun
.close(conn.conn)
put_in(
state.conns,
put_in(
state.conns,
@@
-252,7
+252,7
@@
defmodule Pleroma.Pool.Connections do
nil ->
Logger.debug(":gun_down message for conn which is not found in state")
nil ->
Logger.debug(":gun_down message for conn which is not found in state")
- :ok =
API
.close(conn_pid)
+ :ok =
Gun
.close(conn_pid)
state
end
state
end
@@
-287,7
+287,7
@@
defmodule Pleroma.Pool.Connections do
defp compose_key_gun_info(pid) do
try do
# sometimes :gun.info can raise MatchError, which lead to pool terminate
defp compose_key_gun_info(pid) do
try do
# sometimes :gun.info can raise MatchError, which lead to pool terminate
- %{origin_host: origin_host, origin_scheme: scheme, origin_port: port} =
API
.info(pid)
+ %{origin_host: origin_host, origin_scheme: scheme, origin_port: port} =
Gun
.info(pid)
host =
case :inet.ntoa(origin_host) do
host =
case :inet.ntoa(origin_host) do
diff --git
a/test/http/adapter_helper/gun_test.exs
b/test/http/adapter_helper/gun_test.exs
index bc7e3f0e03d324102c005be4801d43e4010df832..66ca416d960b619c0666312f0e2c4dc5f8cc251c 100644
(file)
--- a/
test/http/adapter_helper/gun_test.exs
+++ b/
test/http/adapter_helper/gun_test.exs
@@
-12,7
+12,7
@@
defmodule Pleroma.HTTP.AdapterHelper.GunTest do
alias Pleroma.Pool.Connections
setup_all do
alias Pleroma.Pool.Connections
setup_all do
- {:ok, _} = Registry.start_link(keys: :unique, name: Pleroma.Gun
.API.
Mock)
+ {:ok, _} = Registry.start_link(keys: :unique, name: Pleroma.GunMock)
:ok
end
:ok
end
diff --git
a/test/http/connection_test.exs
b/test/http/connection_test.exs
index 37de11e7a5e5761faffc743a86842d22d36f4360..3f32898cb6ba85bf5630aea07dc1eb086fe04997 100644
(file)
--- a/
test/http/connection_test.exs
+++ b/
test/http/connection_test.exs
@@
-10,7
+10,7
@@
defmodule Pleroma.HTTP.ConnectionTest do
alias Pleroma.HTTP.Connection
setup_all do
alias Pleroma.HTTP.Connection
setup_all do
- {:ok, _} = Registry.start_link(keys: :unique, name: Pleroma.Gun
.API.
Mock)
+ {:ok, _} = Registry.start_link(keys: :unique, name: Pleroma.GunMock)
:ok
end
:ok
end
diff --git
a/test/http_test.exs
b/test/http_test.exs
index 83c27f6e164d9c58066a308a91de578a1e758f22..d45d34f32461cf0bb9242bf429e4d46bf8cc91a5 100644
(file)
--- a/
test/http_test.exs
+++ b/
test/http_test.exs
@@
-61,8
+61,8
@@
defmodule Pleroma.HTTPTest do
describe "connection pools" do
@describetag :integration
describe "connection pools" do
@describetag :integration
- clear_config(Pleroma.Gun
.API
) do
- Pleroma.Config.put(Pleroma.Gun
.API, Pleroma.Gun
)
+ clear_config(Pleroma.Gun) do
+ Pleroma.Config.put(Pleroma.Gun
, Pleroma.Gun.API
)
end
test "gun" do
end
test "gun" do
diff --git
a/test/pool/connections_test.exs
b/test/pool/connections_test.exs
index a084f31b9f0a9ec59bdd2d2e70f69878ec58337d..31dd5f6facf95a8572144e1fca9e64be14f6aa35 100644
(file)
--- a/
test/pool/connections_test.exs
+++ b/
test/pool/connections_test.exs
@@
-6,12
+6,11
@@
defmodule Pleroma.Pool.ConnectionsTest do
use ExUnit.Case
use Pleroma.Tests.Helpers
import ExUnit.CaptureLog
use ExUnit.Case
use Pleroma.Tests.Helpers
import ExUnit.CaptureLog
- alias Pleroma.Gun.API
alias Pleroma.Gun.Conn
alias Pleroma.Pool.Connections
setup_all do
alias Pleroma.Gun.Conn
alias Pleroma.Pool.Connections
setup_all do
- {:ok, _} = Registry.start_link(keys: :unique, name:
API.
Mock)
+ {:ok, _} = Registry.start_link(keys: :unique, name:
Pleroma.Gun
Mock)
:ok
end
:ok
end
@@
-439,8
+438,8
@@
defmodule Pleroma.Pool.ConnectionsTest do
describe "integration test" do
@describetag :integration
describe "integration test" do
@describetag :integration
- clear_config(
API
) do
- Pleroma.Config.put(
API, Pleroma.Gun
)
+ clear_config(
Pleroma.Gun
) do
+ Pleroma.Config.put(
Pleroma.Gun, Pleroma.Gun.API
)
end
test "opens connection and change owner", %{name: name} do
end
test "opens connection and change owner", %{name: name} do
diff --git
a/test/reverse_proxy/client/tesla_test.exs
b/test/reverse_proxy/client/tesla_test.exs
index 231271b0d29dacd8e96417d89d0a4e40288d3c56..78bd315306154bf8cdc6df0e82c9527eaf8a0e05 100644
(file)
--- a/
test/reverse_proxy/client/tesla_test.exs
+++ b/
test/reverse_proxy/client/tesla_test.exs
@@
-8,8
+8,8
@@
defmodule Pleroma.ReverseProxy.Client.TeslaTest do
alias Pleroma.ReverseProxy.Client
@moduletag :integration
alias Pleroma.ReverseProxy.Client
@moduletag :integration
- clear_config_all(Pleroma.Gun
.API
) do
- Pleroma.Config.put(Pleroma.Gun
.API, Pleroma.Gun
)
+ clear_config_all(Pleroma.Gun) do
+ Pleroma.Config.put(Pleroma.Gun
, Pleroma.Gun.API
)
end
setup do
end
setup do
diff --git
a/test/reverse_proxy/reverse_proxy_test.exs
b/test/reverse_proxy/reverse_proxy_test.exs
index f61fc02c513e9d822cad195656ede0f0dfd1666c..8e72698ee89c6a0f8d5eaed68416e076500a4fff 100644
(file)
--- a/
test/reverse_proxy/reverse_proxy_test.exs
+++ b/
test/reverse_proxy/reverse_proxy_test.exs
@@
-349,8
+349,8
@@
defmodule Pleroma.ReverseProxyTest do
Pleroma.Config.put(Pleroma.ReverseProxy.Client, Pleroma.ReverseProxy.Client.Tesla)
end
Pleroma.Config.put(Pleroma.ReverseProxy.Client, Pleroma.ReverseProxy.Client.Tesla)
end
- clear_config(Pleroma.Gun
.API
) do
- Pleroma.Config.put(Pleroma.Gun
.API, Pleroma.Gun
)
+ clear_config(Pleroma.Gun) do
+ Pleroma.Config.put(Pleroma.Gun
, Pleroma.Gun.API
)
end
setup do
end
setup do
diff --git
a/lib/pleroma/gun/api/mock.ex
b/test/support/gun_mock.ex
similarity index 79%
rename from
lib/pleroma/gun/api/mock.ex
rename to
test/support/gun_mock.ex
index 6d24b0e69afbd1fb4b83d0b2177a8a778e77476e..e13afd08cdbc3d628ecd9bc49e401fbcf1f939e1 100644
(file)
--- a/
lib/pleroma/gun/api/mock.ex
+++ b/
test/support/gun_mock.ex
@@
-2,16
+2,17
@@
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Gun
.API.
Mock do
- @behaviour Pleroma.Gun
.API
+defmodule Pleroma.GunMock do
+ @behaviour Pleroma.Gun
- alias Pleroma.Gun.API
+ alias Pleroma.Gun
+ alias Pleroma.GunMock
- @impl
API
+ @impl
Gun
def open('some-domain.com', 443, _) do
{:ok, conn_pid} = Task.start_link(fn -> Process.sleep(1_000) end)
def open('some-domain.com', 443, _) do
{:ok, conn_pid} = Task.start_link(fn -> Process.sleep(1_000) end)
- Registry.register(
API.
Mock, conn_pid, %{
+ Registry.register(
Gun
Mock, conn_pid, %{
origin_scheme: "https",
origin_host: 'some-domain.com',
origin_port: 443
origin_scheme: "https",
origin_host: 'some-domain.com',
origin_port: 443
@@
-20,7
+21,7
@@
defmodule Pleroma.Gun.API.Mock do
{:ok, conn_pid}
end
{:ok, conn_pid}
end
- @impl
API
+ @impl
Gun
def open(ip, port, _)
when ip in [{10_755, 10_368, 61_708, 131, 64_206, 45_068, 0, 9_694}, {127, 0, 0, 1}] and
port in [80, 443] do
def open(ip, port, _)
when ip in [{10_755, 10_368, 61_708, 131, 64_206, 45_068, 0, 9_694}, {127, 0, 0, 1}] and
port in [80, 443] do
@@
-28,7
+29,7
@@
defmodule Pleroma.Gun.API.Mock do
scheme = if port == 443, do: "https", else: "http"
scheme = if port == 443, do: "https", else: "http"
- Registry.register(
API.
Mock, conn_pid, %{
+ Registry.register(
Gun
Mock, conn_pid, %{
origin_scheme: scheme,
origin_host: ip,
origin_port: port
origin_scheme: scheme,
origin_host: ip,
origin_port: port
@@
-37,7
+38,7
@@
defmodule Pleroma.Gun.API.Mock do
{:ok, conn_pid}
end
{:ok, conn_pid}
end
- @impl
API
+ @impl
Gun
def open('localhost', 1234, %{
protocols: [:socks],
proxy: {:socks5, 'localhost', 1234},
def open('localhost', 1234, %{
protocols: [:socks],
proxy: {:socks5, 'localhost', 1234},
@@
-45,7
+46,7
@@
defmodule Pleroma.Gun.API.Mock do
}) do
{:ok, conn_pid} = Task.start_link(fn -> Process.sleep(1_000) end)
}) do
{:ok, conn_pid} = Task.start_link(fn -> Process.sleep(1_000) end)
- Registry.register(
API.
Mock, conn_pid, %{
+ Registry.register(
Gun
Mock, conn_pid, %{
origin_scheme: "http",
origin_host: 'proxy-socks.com',
origin_port: 80
origin_scheme: "http",
origin_host: 'proxy-socks.com',
origin_port: 80
@@
-54,7
+55,7
@@
defmodule Pleroma.Gun.API.Mock do
{:ok, conn_pid}
end
{:ok, conn_pid}
end
- @impl
API
+ @impl
Gun
def open('localhost', 1234, %{
protocols: [:socks],
proxy: {:socks4, 'localhost', 1234},
def open('localhost', 1234, %{
protocols: [:socks],
proxy: {:socks4, 'localhost', 1234},
@@
-69,7
+70,7
@@
defmodule Pleroma.Gun.API.Mock do
}) do
{:ok, conn_pid} = Task.start_link(fn -> Process.sleep(1_000) end)
}) do
{:ok, conn_pid} = Task.start_link(fn -> Process.sleep(1_000) end)
- Registry.register(
API.
Mock, conn_pid, %{
+ Registry.register(
Gun
Mock, conn_pid, %{
origin_scheme: "https",
origin_host: 'proxy-socks.com',
origin_port: 443
origin_scheme: "https",
origin_host: 'proxy-socks.com',
origin_port: 443
@@
-78,14
+79,14
@@
defmodule Pleroma.Gun.API.Mock do
{:ok, conn_pid}
end
{:ok, conn_pid}
end
- @impl
API
+ @impl
Gun
def open('gun-not-up.com', 80, _opts), do: {:error, :timeout}
def open('gun-not-up.com', 80, _opts), do: {:error, :timeout}
- @impl
API
+ @impl
Gun
def open('example.com', port, _) when port in [443, 115] do
{:ok, conn_pid} = Task.start_link(fn -> Process.sleep(1_000) end)
def open('example.com', port, _) when port in [443, 115] do
{:ok, conn_pid} = Task.start_link(fn -> Process.sleep(1_000) end)
- Registry.register(
API.
Mock, conn_pid, %{
+ Registry.register(
Gun
Mock, conn_pid, %{
origin_scheme: "https",
origin_host: 'example.com',
origin_port: 443
origin_scheme: "https",
origin_host: 'example.com',
origin_port: 443
@@
-94,11
+95,11
@@
defmodule Pleroma.Gun.API.Mock do
{:ok, conn_pid}
end
{:ok, conn_pid}
end
- @impl
API
+ @impl
Gun
def open(domain, 80, _) do
{:ok, conn_pid} = Task.start_link(fn -> Process.sleep(1_000) end)
def open(domain, 80, _) do
{:ok, conn_pid} = Task.start_link(fn -> Process.sleep(1_000) end)
- Registry.register(
API.
Mock, conn_pid, %{
+ Registry.register(
Gun
Mock, conn_pid, %{
origin_scheme: "http",
origin_host: domain,
origin_port: 80
origin_scheme: "http",
origin_host: domain,
origin_port: 80
@@
-107,48
+108,48
@@
defmodule Pleroma.Gun.API.Mock do
{:ok, conn_pid}
end
{:ok, conn_pid}
end
- @impl
API
+ @impl
Gun
def open({127, 0, 0, 1}, 8123, _) do
Task.start_link(fn -> Process.sleep(1_000) end)
end
def open({127, 0, 0, 1}, 8123, _) do
Task.start_link(fn -> Process.sleep(1_000) end)
end
- @impl
API
+ @impl
Gun
def open('localhost', 9050, _) do
Task.start_link(fn -> Process.sleep(1_000) end)
end
def open('localhost', 9050, _) do
Task.start_link(fn -> Process.sleep(1_000) end)
end
- @impl
API
+ @impl
Gun
def await_up(_pid, _timeout), do: {:ok, :http}
def await_up(_pid, _timeout), do: {:ok, :http}
- @impl
API
+ @impl
Gun
def set_owner(_pid, _owner), do: :ok
def set_owner(_pid, _owner), do: :ok
- @impl
API
+ @impl
Gun
def connect(pid, %{host: _, port: 80}) do
ref = make_ref()
def connect(pid, %{host: _, port: 80}) do
ref = make_ref()
- Registry.register(
API.
Mock, ref, pid)
+ Registry.register(
Gun
Mock, ref, pid)
ref
end
ref
end
- @impl
API
+ @impl
Gun
def connect(pid, %{host: _, port: 443, protocols: [:http2], transport: :tls}) do
ref = make_ref()
def connect(pid, %{host: _, port: 443, protocols: [:http2], transport: :tls}) do
ref = make_ref()
- Registry.register(
API.
Mock, ref, pid)
+ Registry.register(
Gun
Mock, ref, pid)
ref
end
ref
end
- @impl
API
+ @impl
Gun
def await(pid, ref) do
def await(pid, ref) do
- [{_, ^pid}] = Registry.lookup(
API.
Mock, ref)
+ [{_, ^pid}] = Registry.lookup(
Gun
Mock, ref)
{:response, :fin, 200, []}
end
{:response, :fin, 200, []}
end
- @impl
API
+ @impl
Gun
def info(pid) do
def info(pid) do
- [{_, info}] = Registry.lookup(
API.
Mock, pid)
+ [{_, info}] = Registry.lookup(
Gun
Mock, pid)
info
end
info
end
- @impl
API
+ @impl
Gun
def close(_pid), do: :ok
end
def close(_pid), do: :ok
end