Skip to content

Commit

Permalink
fix: send headers after
Browse files Browse the repository at this point in the history
  • Loading branch information
loks0n committed Nov 8, 2024
1 parent 72239fb commit 238c9c2
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,40 +532,31 @@ 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]) &&
strlen($body) > $this->compressionMinSize
) {
$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;
Expand Down

0 comments on commit 238c9c2

Please sign in to comment.