diff --git a/src/AssetResponder.php b/src/AssetResponder.php index d4989a4..289d062 100644 --- a/src/AssetResponder.php +++ b/src/AssetResponder.php @@ -2,7 +2,8 @@ namespace Hkt\Psr7Asset; use Psr\Http\Message\ResponseInterface; -use Zend\Diactoros\Stream; +use Zend\Diactoros\CallbackStream; +use SplFileObject; /** * @@ -95,9 +96,18 @@ protected function isValidAsset() */ protected function ok(ResponseInterface $response) { + $path = $this->data->asset->path; + $callable = function () use ($path) { + $file = new SplFileObject($path); + while (! $file->eof()) { + echo $file->fgets(); + } + + return ''; + }; return $response ->withStatus(200) - ->withBody(new Stream($this->data->asset->path)) + ->withBody(new CallbackStream($callable)) ->withHeader('Content-Length', (string) filesize($this->data->asset->path)) ->withHeader('Content-Type', $this->data->asset->type) ; diff --git a/tests/src/AssetResponderTest.php b/tests/src/AssetResponderTest.php index 3752fea..1cb2451 100644 --- a/tests/src/AssetResponderTest.php +++ b/tests/src/AssetResponderTest.php @@ -43,7 +43,11 @@ public function test__invoke_Ok() $actual = $response->getHeaderLine('Content-Type'); $this->assertSame($type, $actual); - $actual = (string) $response->getBody(); + ob_start(); + (string) $response->getBody(); + $actual = ob_get_contents(); + ob_end_clean(); + $expect = file_get_contents($path); $this->assertSame($expect, $actual); }