Merge pull request 'fix(http): treat an empty proxy_url as no proxy' (#8010) from lambadalambda/pleroma:fix/empty-proxy-url into develop

Reviewed-on: https://git.pleroma.social/pleroma/pleroma/pulls/8010
This commit is contained in:
lain 2026-10-29 06:39:21 +00:00
commit 24038667b2
4 changed files with 17 additions and 2 deletions

View file

@ -0,0 +1 @@
HTTP: treat an empty proxy_url as no proxy; with Hackney 4 it made every outgoing request fail

View file

@ -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 """

View file

@ -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)

View file

@ -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