From 0cf9ff0de35fbc99f2783d32a1eb151f622322f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Lochm=C3=BCller?= Date: Sun, 7 Dec 2025 21:31:55 +0100 Subject: [PATCH] [Platform] Respect SSE comments in streaming mode --- src/platform/src/Result/RawHttpResult.php | 5 +++++ src/platform/tests/Result/StreamResultTest.php | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/platform/src/Result/RawHttpResult.php b/src/platform/src/Result/RawHttpResult.php index cf3ced9224..3969d7b055 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 1ae3deac03..bb03f07686 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]); + } }