moonbitstack/moonhttp/sse does not have a README file

    Event

    pub(all) struct Event {
    data : String
    kind : String?
    id : String?
    retry : Int?
    comment : String?
    } derive(Eq,
    Debug
    )

    One event on the wire.

    A field left None is left out of the frame. data carrying newlines goes out as several data: lines and comes back joined, which is the format's own rule and the reason a payload with a blank line in it cannot be sent as one.

    Event::encode

    fn Event::encode(self : Event, space? : Bool) -> String

    The frame this event is sent as, ending in the blank line that dispatches it.

    space writes the one optional space after each colon, which every stream in the wild carries and which a reader strips again. Turning it off saves a byte per field on a stream where that matters, and changes nothing a client sees.

    Event::equal

    fn Event::equal(Event, Event) -> Bool

    Event::new

    fn Event::new(data? : String, kind? : String, id? : String, retry? : Int, comment? : String) -> Event

    An event with whichever fields are wanted.

    Event::not_equal

    fn Event::not_equal(x : Event, y : Event) -> Bool

    Event::of

    fn Event::of(data : String) -> Event

    An event carrying only data, which is the common case.

    Event::ping

    fn Event::ping(comment? : String) -> Event

    A comment-only frame: nothing is dispatched and the connection stays warm.

    Event::to_repr

    decode

    fn decode(input : StringView) -> Array[Event]

    Read a stream of frames.

    Anything the format does not define is ignored rather than refused — an unknown field name, a line with no colon, a stray carriage return. That is what the specification says to do, and it is what lets the format grow.

    A trailing partial frame, one not yet closed by a blank line, is left out: it has not been dispatched and is not an event yet.

    events

    fn events(input : StringView) -> Array[Event]

    The events an EventSource dispatches from a stream: what a browser hands its listeners, where [decode] answers the frames as they were written.

    Three rules differ, all from the specification's "Interpreting an event stream". A frame with no data: line dispatches nothing, so a comment or a lone retry: is not an event. The type is always set, message when the frame named none or named the empty string. And id and retry are the stream's, not the frame's: each holds the last value the stream set until a later line changes it, which is what a client sends back as Last-Event-ID and waits before reconnecting.

    A trailing frame not yet closed by a blank line is left out, as in decode.

    media_type

    let media_type : String

    The media type an event stream is served as.

    Source Files