Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Http/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Utopia\Http;

use Utopia\Compression\Algorithms\Brotli;
use Utopia\Compression\Algorithms\Zstd;
use Utopia\Compression\Compression;

abstract class Response
Expand Down Expand Up @@ -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));
Expand Down
Loading