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));