added unit test, corrected other response logic

pull/572/head
n0nag0n 10 months ago
parent 3659a76106
commit 77d313190d

@ -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
}

@ -26,6 +26,7 @@
<exclude name="Generic.Commenting.DocComment.ContentBeforeClose" />
<exclude name="Generic.Commenting.DocComment.MissingShort" />
<exclude name="Generic.Commenting.DocComment.SpacingBeforeShort" />
<exclude name="Generic.Formatting.NoSpaceAfterCast.SpaceFound" />
<exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine" />
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning" />
<exclude name="Generic.Functions.OpeningFunctionBraceBsdAllman.BraceOnSameLine" />

@ -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();

Loading…
Cancel
Save