Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/platform/src/Result/RawHttpResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/platform/tests/Result/StreamResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Loading