Skip to content

Commit 9112676

Browse files
committed
feat: supported compression algorithms
1 parent 10036b0 commit 9112676

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

src/App.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class App
109109
*/
110110
protected bool $compression = false;
111111
protected int $compressionMinSize = App::COMPRESSION_MIN_SIZE_DEFAULT;
112+
protected mixed $compressionSupported;
112113

113114
/**
114115
* App
@@ -136,6 +137,14 @@ public function setCompressionMinSize(int $compressionMinSize)
136137
$this->compressionMinSize = $compressionMinSize;
137138
}
138139

140+
/**
141+
* Set supported compression algorithms
142+
*/
143+
public function setCompressionSupported(mixed $compressionSupported)
144+
{
145+
$this->compressionSupported = $compressionSupported;
146+
}
147+
139148
/**
140149
* GET
141150
*
@@ -669,6 +678,7 @@ public function run(Request $request, Response $response): static
669678
if ($this->compression) {
670679
$response->setAcceptEncoding($request->getHeader('accept-encoding', ''));
671680
$response->setCompressionMinSize($this->compressionMinSize);
681+
$response->setCompressionSupported($this->compressionSupported);
672682
}
673683

674684
$this->resources['request'] = $request;

src/Response.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ class Response
257257
*/
258258
protected int $compressionMinSize = App::COMPRESSION_MIN_SIZE_DEFAULT;
259259

260+
/**
261+
* @var mixed
262+
*/
263+
protected mixed $compressionSupported;
264+
260265
/**
261266
* Response constructor.
262267
*
@@ -308,6 +313,17 @@ public function setCompressionMinSize(int $compressionMinSize): static
308313
return $this;
309314
}
310315

316+
/**
317+
* Set supported compression algorithms
318+
*
319+
* @param mixed $compressionSupported
320+
*/
321+
public function setCompressionSupported(mixed $compressionSupported): static
322+
{
323+
$this->compressionSupported = $compressionSupported;
324+
return $this;
325+
}
326+
311327
/**
312328
* Get content type
313329
*
@@ -529,11 +545,7 @@ public function send(string $body = ''): void
529545
isset($this->compressed[$this->contentType]) &&
530546
strlen($body) > $this->compressionMinSize
531547
) {
532-
$algorithm = Compression::fromAcceptEncoding($this->acceptEncoding, [
533-
Compression::BROTLI,
534-
Compression::GZIP,
535-
Compression::DEFLATE,
536-
]);
548+
$algorithm = Compression::fromAcceptEncoding($this->acceptEncoding, $this->compressionSupported);
537549

538550
if ($algorithm) {
539551
$body = $algorithm->compress($body);

0 commit comments

Comments
 (0)