From 3c0046ed3b6ca7abba48d5797672bdb1343e6bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <1005065+DeepDiver1975@users.noreply.github.com> Date: Wed, 3 May 2023 18:05:03 +0200 Subject: [PATCH] feat: enable http compression by sending data not with chunked encoding - if possible --- src/Swoole/SwooleClient.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Swoole/SwooleClient.php b/src/Swoole/SwooleClient.php index a0e25bb4a..7afbf656a 100644 --- a/src/Swoole/SwooleClient.php +++ b/src/Swoole/SwooleClient.php @@ -260,12 +260,15 @@ protected function sendResponseContent(OctaneResponse $octaneResponse, SwooleRes return; } + // if the content fits into one chunk -> perform no chunked encoding if ($length <= $this->chunkSize) { - $swooleResponse->write($content); - } else { - for ($offset = 0; $offset < $length; $offset += $this->chunkSize) { - $swooleResponse->write(substr($content, $offset, $this->chunkSize)); - } + $swooleResponse->end($content); + + return; + } + + for ($offset = 0; $offset < $length; $offset += $this->chunkSize) { + $swooleResponse->write(substr($content, $offset, $this->chunkSize)); } $swooleResponse->end();