diff --git a/src/bridge/symfony/http-foundation/src/Flow/Bridge/Symfony/HttpFoundation/Response/FlowBufferedResponse.php b/src/bridge/symfony/http-foundation/src/Flow/Bridge/Symfony/HttpFoundation/Response/FlowBufferedResponse.php index 23b9d91d4..82101e034 100644 --- a/src/bridge/symfony/http-foundation/src/Flow/Bridge/Symfony/HttpFoundation/Response/FlowBufferedResponse.php +++ b/src/bridge/symfony/http-foundation/src/Flow/Bridge/Symfony/HttpFoundation/Response/FlowBufferedResponse.php @@ -60,6 +60,17 @@ private function evaluate() : void ->write($this->output->memoryLoader($id = \bin2hex(\random_bytes(16)) . '.memory')) ->run(); - $this->content = $config->fstab()->for(protocol('memory'))->readFrom(path_memory($id))->content(); + $fs = $config->fstab()->for(protocol('memory')); + + if ($fs->status(path_memory($id)) === null) { + $this->buffered = true; + $this->content = ''; + $this->statusCode = self::HTTP_NO_CONTENT; + + return; + } + + $this->content = $fs->readFrom(path_memory($id))->content(); + $this->buffered = true; } } diff --git a/src/bridge/symfony/http-foundation/tests/Flow/Bridge/Symfony/HttpFoundation/Tests/Unit/Response/FlowBufferedResponseTest.php b/src/bridge/symfony/http-foundation/tests/Flow/Bridge/Symfony/HttpFoundation/Tests/Unit/Response/FlowBufferedResponseTest.php new file mode 100644 index 000000000..fd69e62b3 --- /dev/null +++ b/src/bridge/symfony/http-foundation/tests/Flow/Bridge/Symfony/HttpFoundation/Tests/Unit/Response/FlowBufferedResponseTest.php @@ -0,0 +1,38 @@ +response(http_json_output()); + + self::assertEquals('', $response->getContent()); + self::assertEquals(204, $response->getStatusCode()); + } + + public function test_response_is_buffered_only_once() : void + { + $extractor = $this->createMock(Extractor::class); + + $extractor->expects(self::once())->method('extract')->willReturn((function () : \Generator { + yield rows(row(int_entry('id', 1))); + })()); + + $response = http_stream_open($extractor)->response(http_json_output()); + + $response->getContent(); + $response->getContent(); + + self::assertEquals('[{"id":1}]', $response->getContent()); + self::assertEquals(200, $response->getStatusCode()); + } +} diff --git a/src/bridge/symfony/http-foundation/tests/Flow/Bridge/Symfony/HttpFoundation/Tests/Unit/Response/FlowStreamedResponseTest.php b/src/bridge/symfony/http-foundation/tests/Flow/Bridge/Symfony/HttpFoundation/Tests/Unit/Response/FlowStreamedResponseTest.php new file mode 100644 index 000000000..5bd93497c --- /dev/null +++ b/src/bridge/symfony/http-foundation/tests/Flow/Bridge/Symfony/HttpFoundation/Tests/Unit/Response/FlowStreamedResponseTest.php @@ -0,0 +1,20 @@ +streamedResponse(http_json_output()); + + self::assertEquals('', $response->getContent()); + self::assertEquals(200, $response->getStatusCode()); + } +}