Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for SSE Routes #1245

Closed
Badgerati opened this issue Feb 24, 2024 · 0 comments · Fixed by #1256
Closed

Support for SSE Routes #1245

Badgerati opened this issue Feb 24, 2024 · 0 comments · Fixed by #1256
Assignees
Milestone

Comments

@Badgerati
Copy link
Owner

Support in Routes should be allowed to enable SSE, and only on GET Routes.

as an example, some Set-PodeSseConnection function could be called from an Add-PodeRoute scriptblock which would set appropriate the Content-Type = text/event-stream header, as well as Cache-Control = no-cache; Connection = keep-alive; and Access-Control-Allow-Origin = * (if needed). A ClientId would also be generated for the connection, and set back as X-Pode-ClientId similar to websockets. This function would also ensure that the Request Headers contain an Accept = text/event-stream header, and that the Method = GET, otherwise the call should fail.

The above function could also check for a Last-Event-Id header on the Request. A new $WebEvent.Sse property could be populated with such info.

Pode would then internal keep the inbound connection open, mapped against the Event Type and ClientId. A new Send-PodeSseMessage could be used to send messages from server-to-client(s), with optional ID/Event messages as well. Similar to websockets, these messages will be sent asynchronously, in case there are a lot of clients to sent messages to.

A Close-PodeSseConnection function could be used to close an open client connection, or all connections for an event type.

Optional: an Add-PodeSseRoute wrapper function for Add-PodeRoute, which will automatically deal the simple SSE Route configurations - ie: just Set-PodeSseConnection.

Docs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant