diff --git a/flight/net/Response.php b/flight/net/Response.php
index d5d3afa..1798de5 100644
--- a/flight/net/Response.php
+++ b/flight/net/Response.php
@@ -341,6 +341,15 @@ class Response
);
}
+ if ($this->content_length === true) {
+ // Send content length
+ $length = $this->getContentLength();
+
+ if ($length > 0) {
+ $this->setHeader('Content-Length', (string) $length);
+ }
+ }
+
// Send other headers
foreach ($this->headers as $field => $value) {
if (\is_array($value)) {
@@ -352,15 +361,6 @@ class Response
}
}
- if ($this->content_length) {
- // Send content length
- $length = $this->getContentLength();
-
- if ($length > 0) {
- $this->setRealHeader('Content-Length: ' . $length);
- }
- }
-
return $this;
}
@@ -437,7 +437,7 @@ class Response
$this->processResponseCallbacks();
}
- if (!headers_sent()) {
+ if (headers_sent() === false) {
$this->sendHeaders(); // @codeCoverageIgnore
}
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index bafe06d..79f3ff0 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -26,6 +26,7 @@
+
diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php
index 3226cc9..443ff89 100644
--- a/tests/ResponseTest.php
+++ b/tests/ResponseTest.php
@@ -270,6 +270,22 @@ class ResponseTest extends TestCase
$this->assertEquals('grfg', $rot13_body);
}
+ public function testResponseBodyCallbackGzip()
+ {
+ $response = new Response();
+ $response->content_length = true;
+ $response->write('test');
+ $gzip = function ($body) {
+ return gzencode($body);
+ };
+ $response->addResponseBodyCallback($gzip);
+ ob_start();
+ $response->send();
+ $gzip_body = ob_get_clean();
+ $this->assertEquals('H4sIAAAAAAAAAytJLS4BAAx+f9gEAAAA', base64_encode($gzip_body));
+ $this->assertEquals(strlen(gzencode('test')), strlen($gzip_body));
+ }
+
public function testResponseBodyCallbackMultiple()
{
$response = new Response();