diff --git a/src/platform/src/Result/RawHttpResult.php b/src/platform/src/Result/RawHttpResult.php index cf3ced922..3969d7b05 100644 --- a/src/platform/src/Result/RawHttpResult.php +++ b/src/platform/src/Result/RawHttpResult.php @@ -55,6 +55,11 @@ public function getDataStream(): iterable continue; } + if (str_starts_with(trim($delta), ':')) { + // SEE comments via Spec https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation + continue; + } + yield json_decode($delta, true, flags: \JSON_THROW_ON_ERROR); } } diff --git a/src/platform/tests/Result/StreamResultTest.php b/src/platform/tests/Result/StreamResultTest.php index 1ae3deac0..bb03f0768 100644 --- a/src/platform/tests/Result/StreamResultTest.php +++ b/src/platform/tests/Result/StreamResultTest.php @@ -32,4 +32,22 @@ public function testGetContent() $this->assertSame('data1', $content[0]); $this->assertSame('data2', $content[1]); } + + public function testGetContentInclSseComments() + { + $generator = (static function () { + yield 'data1'; + yield ': this is just a comment'; + yield 'data2'; + })(); + + $result = new StreamResult($generator); + $this->assertInstanceOf(\Generator::class, $result->getContent()); + + $content = iterator_to_array($result->getContent()); + + $this->assertCount(2, $content); + $this->assertSame('data1', $content[0]); + $this->assertSame('data2', $content[1]); + } }