Class SseFrameParser
- Namespace
- SseAssertions
- Assembly
- SseAssertions.dll
Parses a Server-Sent Events wire-format string into a sequence of SseEvent instances per the WHATWG / W3C SSE specification.
public static class SseFrameParser
- Inheritance
-
SseFrameParser
- Inherited Members
Remarks
The parser handles all three line terminators (\r\n, \r, \n), strips a
single leading UTF-8 BOM (U+FEFF) when present at offset 0, ignores comment lines
(lines starting with :), and treats unknown field names as no-ops per spec. The
event:, data:, id:, and retry: directives are recognised; on a
blank line the accumulated frame is dispatched as an SseEvent (with
EventName defaulting to "message" per the WHATWG default when
no event: directive was present), unless no data: line was seen — in which case
the frame is dropped per spec.
Per-event semantics for id: and retry:: an SseEvent carries an
Id or RetryMillis value only when the
corresponding directive appeared in that frame. This is a small but deliberate deviation from
the browser model (where last-event-id and reconnection-time are stream-wide state): the
assertion library exposes the wire-format directives as observed, so consumers can write
HasSseEvent("retry").WithRetryMillis(r => r == 5000)-style assertions.
Methods
Parse(string)
Parses an SSE wire-format string into a sequence of SseEvent
instances. Eagerly materialised; the parser does not retain a reference to
body.
public static IReadOnlyList<SseEvent> Parse(string body)
Parameters
bodystringThe SSE wire-format text. May be empty (returns an empty list).
Returns
- IReadOnlyList<SseEvent>
The parsed events in document order.
Exceptions
- ArgumentNullException
bodyis null.