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.
This commit is contained in:
parent
b2e4580a81
commit
532762bd9b
2 changed files with 19 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue