From d9509f42668d65fbedafa54649cf029373bf01ec Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sun, 19 Apr 2026 20:40:44 +0100 Subject: [PATCH] Lower Brotli default compression level to 4 Brotli defaulted to level 11 (near-max), which is too slow for an HTTP response path. Set a fast, HTTP-sensible default of 4 and add an explicit Zstd default of 3. GZIP and Deflate have no public level setter in utopia-php/compression 0.1.4, so their PHP defaults (6) are left as-is. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/Http/Http.php | 2 ++ src/Http/Response.php | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/Http/Http.php b/src/Http/Http.php index 7ce6f0e..7bdd100 100755 --- a/src/Http/Http.php +++ b/src/Http/Http.php @@ -15,6 +15,8 @@ class Http { public const COMPRESSION_MIN_SIZE_DEFAULT = 1024; + public const COMPRESSION_BROTLI_LEVEL_DEFAULT = 4; + public const COMPRESSION_ZSTD_LEVEL_DEFAULT = 3; /** * Request method constants diff --git a/src/Http/Response.php b/src/Http/Response.php index 9d5edf0..4199685 100755 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -2,6 +2,8 @@ namespace Utopia\Http; +use Utopia\Compression\Algorithms\Brotli; +use Utopia\Compression\Algorithms\Zstd; use Utopia\Compression\Compression; abstract class Response @@ -625,6 +627,12 @@ public function send(string $body = ''): void $algorithm = Compression::fromAcceptEncoding($this->acceptEncoding, $this->compressionSupported); if ($algorithm) { + if ($algorithm instanceof Brotli) { + $algorithm->setLevel(Http::COMPRESSION_BROTLI_LEVEL_DEFAULT); + } elseif ($algorithm instanceof Zstd) { + $algorithm->setLevel(Http::COMPRESSION_ZSTD_LEVEL_DEFAULT); + } + $body = $algorithm->compress($body); $this->removeHeader('Content-Length'); $this->addHeader('Content-Length', (string) \strlen($body));