From 532762bd9b66e76a1cba4a22983446e1c30d26f4 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Thu, 22 Oct 2026 16:36:16 +0400 Subject: [PATCH] fix(http): keep the configured TLS options with Gun [:http, :adapter, :ssl_options] is Hackney's key, and AdminFE sets it. Gun reads tls_opts, so with Gun as the default these settings were lost without a warning. Use them as tls_opts unless tls_opts is set. --- lib/pleroma/http/adapter_helper/gun.ex | 10 ++++++++++ test/pleroma/http/adapter_helper/gun_test.exs | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/pleroma/http/adapter_helper/gun.ex b/lib/pleroma/http/adapter_helper/gun.ex index 9ac87adb5..11efaca88 100644 --- a/lib/pleroma/http/adapter_helper/gun.ex +++ b/lib/pleroma/http/adapter_helper/gun.ex @@ -28,6 +28,7 @@ defmodule Pleroma.HTTP.AdapterHelper.Gun do @defaults |> Keyword.merge(config_opts) + |> ssl_options_to_tls_opts() |> add_scheme_opts(uri) |> AdapterHelper.maybe_add_proxy(proxy) |> Keyword.merge(incoming_opts) @@ -35,6 +36,15 @@ defmodule Pleroma.HTTP.AdapterHelper.Gun do |> maybe_stream() end + # [:http, :adapter, :ssl_options] is Hackney's name for the TLS options, + # and AdminFE sets it. Keep those settings when Gun is the adapter. + defp ssl_options_to_tls_opts(opts) do + case Keyword.pop(opts, :ssl_options) do + {nil, opts} -> opts + {ssl_options, opts} -> Keyword.put_new(opts, :tls_opts, ssl_options) + end + end + defp add_scheme_opts(opts, %{scheme: "http"}), do: opts defp add_scheme_opts(opts, %{scheme: "https"}) do diff --git a/test/pleroma/http/adapter_helper/gun_test.exs b/test/pleroma/http/adapter_helper/gun_test.exs index 1c97daf99..f4f96faeb 100644 --- a/test/pleroma/http/adapter_helper/gun_test.exs +++ b/test/pleroma/http/adapter_helper/gun_test.exs @@ -50,6 +50,15 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do assert Keyword.has_key?(defaults, :b) end + test "uses Hackney's ssl_options from the config as Gun's tls_opts" do + clear_config([:http, :adapter], ssl_options: [versions: [:"tlsv1.3"]]) + + opts = Gun.options([], URI.parse("https://example.com")) + + assert opts[:tls_opts] == [versions: [:"tlsv1.3"]] + refute Keyword.has_key?(opts, :ssl_options) + end + test "parses string proxy host & port" do clear_config([:http, :proxy_url], "localhost:8123")