Skip to content

Commit 49a6bd3

Browse files
loks0nclaude
andauthored
Lower Brotli default compression level to 4 (#238)
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) <noreply@anthropic.com>
1 parent 8754f5f commit 49a6bd3

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/Http/Http.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
class Http
1616
{
1717
public const COMPRESSION_MIN_SIZE_DEFAULT = 1024;
18+
public const COMPRESSION_BROTLI_LEVEL_DEFAULT = 4;
19+
public const COMPRESSION_ZSTD_LEVEL_DEFAULT = 3;
1820

1921
/**
2022
* Request method constants

src/Http/Response.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Utopia\Http;
44

5+
use Utopia\Compression\Algorithms\Brotli;
6+
use Utopia\Compression\Algorithms\Zstd;
57
use Utopia\Compression\Compression;
68

79
abstract class Response
@@ -625,6 +627,12 @@ public function send(string $body = ''): void
625627
$algorithm = Compression::fromAcceptEncoding($this->acceptEncoding, $this->compressionSupported);
626628

627629
if ($algorithm) {
630+
if ($algorithm instanceof Brotli) {
631+
$algorithm->setLevel(Http::COMPRESSION_BROTLI_LEVEL_DEFAULT);
632+
} elseif ($algorithm instanceof Zstd) {
633+
$algorithm->setLevel(Http::COMPRESSION_ZSTD_LEVEL_DEFAULT);
634+
}
635+
628636
$body = $algorithm->compress($body);
629637
$this->removeHeader('Content-Length');
630638
$this->addHeader('Content-Length', (string) \strlen($body));

0 commit comments

Comments
 (0)