Skip to content

feat(http): offer more control over server sent events format#1459

Merged
innocenzi merged 4 commits intotempestphp:mainfrom
thoresuenert:feature/refactor-response-event-streams
Aug 5, 2025
Merged

feat(http): offer more control over server sent events format#1459
innocenzi merged 4 commits intotempestphp:mainfrom
thoresuenert:feature/refactor-response-event-streams

Conversation

@thoresuenert
Copy link
Contributor

The current implementation of the GenericResponseSender hardcoded the server sent event protocoll to:

 echo "event: {$event}\n";
 echo "data: {$data}";
 echo "\n\n";

We cannot use multiple data lines or add something like id or retry to the fields list https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#fields.

I introduced a Interface ServerSentEvent with a hooked property $datalines to move the shape of the data transmitted with a single message into the Event itself.

This change allows us to implement the datastar protocoll for example:

event: datastar-patch-elements
data: elements <div id="hal">
data: elements     I’m sorry, Dave. I’m afraid I can’t do that.
data: elements </div>

@innocenzi innocenzi changed the title feat(http): refactor ServerSentEvents to make custom protocoll implementations possible feat(http): offer more control over server sent events format Aug 5, 2025
@innocenzi innocenzi merged commit 6623850 into tempestphp:main Aug 5, 2025
75 checks passed
@innocenzi
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants