Supporting Server-Sent Events #1554
atombender
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
From what I can see there's no built-in support for SSE endpoints. It's possible to define a response like this:
This causes the response struct to be defined like so:
You can then use an
io.Pipe()to pump data through.The issue is that the HTTP server is buffered, and there's no mechanism to flush the stream. Internally, Ogen just uses an
io.Copy()to pump the reader into the writer. So the client will not get any data until a certain amount of data is written, and it might receive partially written data when the payloads are not exactly at the buffer boundary.I can hack together a middleware that replaces the response writer with an unbuffered one just for the SSE endpoints, but it would be nice to not need that. Are there any other techniques?
Beta Was this translation helpful? Give feedback.
All reactions