Skip to main content

Module sse

Module sse 

Source
Expand description

Server-sent events: Event encodes one event of the text/event-stream format, and Sse streams events as a response.

  • Data may hold any text: each line becomes its own data: line (\n, \r\n and \r all end a line), so a client receives the text back with \n line ends.
  • Event names and ids are single lines: a CR or LF in them (or a NUL in an id, which clients ignore) is rejected with SseError instead of splitting the event.
  • Responses carry Content-Type: text/event-stream and Cache-Control: no-store, so no cache stores or replays a stream.
  • An Err from the event stream ends the response body abruptly; the error itself is never sent (clients see the connection end and may reconnect). Send an event first if the client should know why.
  • Events are pulled only as fast as the connection takes them, so a slow reader never makes the stream buffer events (feed it from a bounded channel, never an unbounded one). A client that disconnects drops the stream, and with it the work behind it.
  • Sse::keep_alive sends a comment after an idle interval, so proxies and clients do not close a quiet connection; Sse::until ends the stream when a future resolves, such as Readiness::stopping(), so graceful shutdown need not time out.

Structs§

Event
One server-sent event.
Sse
A text/event-stream response from a stream of events.

Enums§

SseError
A field value that would break the event framing.

Constants§

EVENT_STREAM
The media type of an event stream.