fix(http): treat an empty proxy_url as no proxy
This commit is contained in:
parent
9edce3a0a6
commit
1c8c6048de
4 changed files with 17 additions and 2 deletions
1
changelog.d/empty-proxy-url.fix
Normal file
1
changelog.d/empty-proxy-url.fix
Normal file
|
|
@ -0,0 +1 @@
|
|||
HTTP: treat an empty proxy_url as no proxy; with Hackney 4 it made every outgoing request fail
|
||||
|
|
@ -20,8 +20,9 @@ defmodule Pleroma.HTTP.AdapterHelper do
|
|||
|
||||
@callback options(keyword(), URI.t()) :: keyword()
|
||||
|
||||
# AdminFE stores an empty proxy field as "", which means no proxy.
|
||||
@spec format_proxy(String.t() | tuple() | nil) :: proxy() | nil
|
||||
def format_proxy(nil), do: nil
|
||||
def format_proxy(proxy) when proxy in [nil, ""], do: nil
|
||||
|
||||
def format_proxy(proxy_url) do
|
||||
case parse_proxy(proxy_url) do
|
||||
|
|
@ -32,7 +33,7 @@ defmodule Pleroma.HTTP.AdapterHelper do
|
|||
end
|
||||
|
||||
@spec maybe_add_proxy(keyword(), proxy() | nil) :: keyword()
|
||||
def maybe_add_proxy(opts, nil), do: opts
|
||||
def maybe_add_proxy(opts, proxy) when proxy in [nil, ""], do: opts
|
||||
def maybe_add_proxy(opts, proxy), do: Keyword.put_new(opts, :proxy, proxy)
|
||||
|
||||
@doc """
|
||||
|
|
|
|||
|
|
@ -58,6 +58,13 @@ defmodule Pleroma.HTTP.AdapterHelper.HackneyTest do
|
|||
{:socks5, ~c"::1", 9050}
|
||||
end
|
||||
|
||||
# AdminFE stores an empty field as "", and Hackney 4 fails every request with it.
|
||||
test "ignores an empty proxy_url", %{uri: uri} do
|
||||
clear_config([:http, :proxy_url], "")
|
||||
|
||||
refute Keyword.has_key?(Hackney.options([], uri), :proxy)
|
||||
end
|
||||
|
||||
test "respect connection opts and no proxy", %{uri: uri} do
|
||||
opts = Hackney.options([a: 2, b: 1], uri)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@ defmodule Pleroma.HTTP.AdapterHelperTest do
|
|||
assert AdapterHelper.format_proxy(nil) == nil
|
||||
end
|
||||
|
||||
test "with an empty string" do
|
||||
assert ExUnit.CaptureLog.capture_log(fn ->
|
||||
assert AdapterHelper.format_proxy("") == nil
|
||||
end) == ""
|
||||
end
|
||||
|
||||
test "with string" do
|
||||
assert AdapterHelper.format_proxy("127.0.0.1:8123") == {{127, 0, 0, 1}, 8123}
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue