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\nand\rall end a line), so a client receives the text back with\nline 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
SseErrorinstead of splitting the event. - Responses carry
Content-Type: text/event-streamandCache-Control: no-store, so no cache stores or replays a stream. - An
Errfrom 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_alivesends a comment after an idle interval, so proxies and clients do not close a quiet connection;Sse::untilends the stream when a future resolves, such asReadiness::stopping(), so graceful shutdown need not time out.
Structs§
Enums§
- SseError
- A field value that would break the event framing.
Constants§
- EVENT_
STREAM - The media type of an event stream.