class

Kemal::EventStream

Inherits Reference < Object

Helper for Server-Sent Events (SSE) responses.

Sets the required headers and formats events according to the SSE spec.

Constructors

Class methods

serve(context : HTTP::Server::Context, & : EventStream, HTTP::Server::Context -> )

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.

Source

Instance methods

close
Source
comment(text : String) : self

Sends a keep-alive comment (ignored by clients, useful during idle periods).

Source
flush
Source
send(data : String, *, event : String | Nil = nil, id : String | Int | Nil = nil, retry : Time::Span | Nil = nil) : self

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.

Source