Skip to content

Commit 578cdec

Browse files
committed
fix: address Greptile review comments on PR #230
- Remove Content-Length before re-adding after compression to prevent duplicate headers - Defer onStart callback into coroutine event loop for SwooleCoroutine adapter consistency - Add null-coalescing fallback for preg_replace in View::render - Add void return types to compression setter methods for API consistency
1 parent 57fc537 commit 578cdec

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/Http/Adapter/SwooleCoroutine/Server.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Server extends Adapter
1414
protected SwooleServer $server;
1515
protected const REQUEST_CONTAINER_CONTEXT_KEY = '__utopia_http_request_container';
1616
protected Container $container;
17+
/** @var callable|null */
18+
protected $onStartCallback = null;
1719

1820
public function __construct(string $host, ?string $port = null, array $settings = [], ?Container $container = null)
1921
{
@@ -55,12 +57,15 @@ public function getServer(): SwooleServer
5557

5658
public function onStart(callable $callback)
5759
{
58-
\call_user_func($callback, $this);
60+
$this->onStartCallback = $callback;
5961
}
6062

6163
public function start()
6264
{
6365
go(function () {
66+
if ($this->onStartCallback) {
67+
\call_user_func($this->onStartCallback, $this);
68+
}
6469
$this->server->start();
6570
});
6671
}

src/Http/Http.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,23 @@ public function __construct(Adapter $server, string $timezone)
152152
/**
153153
* Set Compression
154154
*/
155-
public function setCompression(bool $compression)
155+
public function setCompression(bool $compression): void
156156
{
157157
$this->compression = $compression;
158158
}
159159

160160
/**
161161
* Set minimum compression size
162162
*/
163-
public function setCompressionMinSize(int $compressionMinSize)
163+
public function setCompressionMinSize(int $compressionMinSize): void
164164
{
165165
$this->compressionMinSize = $compressionMinSize;
166166
}
167167

168168
/**
169169
* Set supported compression algorithms
170170
*/
171-
public function setCompressionSupported(mixed $compressionSupported)
171+
public function setCompressionSupported(mixed $compressionSupported): void
172172
{
173173
$this->compressionSupported = $compressionSupported;
174174
}

src/Http/Response.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ public function send(string $body = ''): void
626626

627627
if ($algorithm) {
628628
$body = $algorithm->compress($body);
629+
$this->removeHeader('Content-Length');
629630
$this->addHeader('Content-Length', (string) \strlen($body));
630631
$this->addHeader('Content-Encoding', $algorithm->getContentEncoding());
631632
$this->addHeader('X-Utopia-Compression', 'true');

src/Http/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public function render(bool $minify = true): string
293293
'\\1',
294294
];
295295

296-
$html = \preg_replace($search, $replace, $html);
296+
$html = \preg_replace($search, $replace, $html) ?? $html;
297297

298298
// Replacing back with content
299299
$html = \str_replace(\array_map(function ($el) {

0 commit comments

Comments
 (0)