From b2e4580a81c2b7ecb703d89959ff007aa35be08c Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Thu, 22 Oct 2026 16:31:44 +0400 Subject: [PATCH] feat(http): make Gun the default HTTP client Hackney 4 reads every response completely before Pleroma can check its size, so max_body no longer limits downloads or memory there; Gun stops at the limit. Document the Hackney limitation for those who switch back. --- changelog.d/gun-default.change | 1 + config/config.exs | 2 +- docs/configuration/cheatsheet.md | 11 +++++++++++ test/pleroma/http/default_adapter_test.exs | 13 +++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 changelog.d/gun-default.change create mode 100644 test/pleroma/http/default_adapter_test.exs diff --git a/changelog.d/gun-default.change b/changelog.d/gun-default.change new file mode 100644 index 000000000..97ca20903 --- /dev/null +++ b/changelog.d/gun-default.change @@ -0,0 +1 @@ +Gun is now the default HTTP client instead of Hackney \ No newline at end of file diff --git a/config/config.exs b/config/config.exs index ec176df1d..656e70ff8 100644 --- a/config/config.exs +++ b/config/config.exs @@ -161,7 +161,7 @@ config :mime, :types, %{ "image/apng" => ["apng"] } -config :tesla, adapter: Tesla.Adapter.Hackney +config :tesla, adapter: Tesla.Adapter.Gun # Hackney 4 shares one HTTP/2 connection per host, and closing one response # (as the media proxy does) stops it for every other stream on it. diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md index 0275d2be0..0460caf26 100644 --- a/docs/configuration/cheatsheet.md +++ b/docs/configuration/cheatsheet.md @@ -541,6 +541,15 @@ Available caches: ## HTTP client +Pleroma uses [Gun](https://github.com/ninenines/gun) for outgoing HTTP requests. To use Hackney instead: + +```elixir +config :tesla, adapter: Tesla.Adapter.Hackney +``` + +!!! note + With Hackney, size limits for fetched responses (for example for link previews) are checked only after Hackney has read the whole response. They limit what Pleroma keeps, not how much it downloads or holds in memory. Gun stops reading at the limit. + ### :http * `proxy_url`: an upstream proxy to fetch posts and/or media with, (default: `nil`) @@ -550,6 +559,8 @@ Available caches: ### :hackney_pools +*For `hackney` adapter* + Advanced. Tweaks Hackney (http client) connections pools. There's three pools used: diff --git a/test/pleroma/http/default_adapter_test.exs b/test/pleroma/http/default_adapter_test.exs new file mode 100644 index 000000000..e4f57dfa2 --- /dev/null +++ b/test/pleroma/http/default_adapter_test.exs @@ -0,0 +1,13 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.HTTP.DefaultAdapterTest do + use ExUnit.Case, async: true + + # The test environment uses Tesla.Mock, and config.exs imports the config + # of the current Mix env, so check the shipped default in the file itself. + test "Gun is the default HTTP client" do + assert File.read!("config/config.exs") =~ ~r/^config :tesla, adapter: Tesla.Adapter.Gun$/m + end +end