From 238c9c2040621f0d5286825d2c452310a1c21e2d Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:10:14 +0100 Subject: [PATCH] fix: send headers after --- src/Response.php | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/Response.php b/src/Response.php index 4e1c7f5b..828eea45 100755 --- a/src/Response.php +++ b/src/Response.php @@ -532,19 +532,9 @@ public function send(string $body = ''): void $this->addHeader('Server', $serverHeader); $this->addHeader('X-Debug-Speed', (string) (microtime(true) - $this->startTime)); - $this->appendCookies()->appendHeaders(); - - // Send response - if ($this->disablePayload) { - $this->end(); - return; - } + $this->appendCookies(); // Compress body - Console::log('Accept-Encoding: '.$this->acceptEncoding . ' - ' . $this->compressionMinSize); - Console::log('Content-Type: '.$this->contentType . ' - ' . $this->compressed[$this->contentType]); - Console::log('Content-Length: '.strlen($body) . ' - ' . $this->compressionMinSize); - if ( !empty($this->acceptEncoding) && isset($this->compressed[$this->contentType]) && @@ -552,20 +542,21 @@ public function send(string $body = ''): void ) { $algorithm = Compression::fromAcceptEncoding($this->acceptEncoding, $this->compressionSupported); - Console::log('Compression Algorithm: '.($algorithm ? $algorithm->getName() : 'none')); - if ($algorithm) { - Console::log('Body before compression: '.strlen($body)); - $body = $algorithm->compress($body); - - Console::log('Body after compression: '.strlen($body)); - $this->addHeader('Content-Encoding', $algorithm->getContentEncoding()); $this->addHeader('Vary', 'Accept-Encoding'); } } + $this->appendHeaders(); + + // Send response + if ($this->disablePayload) { + $this->end(); + return; + } + $headerSize = strlen(implode("\n", $this->headers)); $bodyLength = strlen($body); $this->size += $headerSize + $bodyLength;