Kemal::EventStream
Helper for Server-Sent Events (SSE) responses.
Sets the required headers and formats events according to the SSE spec.
Constructors
Class methods
Runs an SSE handler with headers configured and yields an EventStream.
A HEAD request gets the headers of the stream and no stream. The handler is
typically an endless loop that only stops when a write fails because the
client is gone, and on HEAD nothing it writes goes anywhere - the body is
discarded and counted - so the loop would never see the client leave and the
fiber would run for the life of the process.
Instance methods
Sends a keep-alive comment (ignored by clients, useful during idle periods).
Sends an SSE event. Multi-line data is split into separate data: fields.
event and id must not contain CR/LF; newlines there raise ArgumentError
so they cannot inject SSE fields. A negative retry span is omitted from the
output, since clients discard non-digit retry values anyway.