Sign in

    gaato/http/sse does not have a README file

    SseEvent

    pub(all) struct SseEvent {
    event : String
    data : String
    id : String?
    retry : Int?
    } derive(Eq,
    Debug
    )

    A dispatched event, with resolved type and the current last-event-id. Retry is the last valid retry seen since the previous dispatched event, in milliseconds, capped at one hour.

    SseEvent::equal

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

    Compares all event fields.

    SseEvent::not_equal

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

    Compares all event fields.

    SseEvent::to_repr

    Debug representation of an event.

    SseParser

    pub struct SseParser {
    // private fields
    }

    An incremental UTF-8 event-stream parser. Create one parser per stream.

    SseParser::feed

    fn SseParser::feed(self : SseParser, bytes : Bytes) -> Array[SseEvent] raise
    HttpError

    Feeds any byte chunk and returns complete events in order. Malformed UTF-8 is replaced with U+FFFD. Feeding after finish is a no-op.

    An event over max_event_bytes raises Protocol and ends the stream, which is refused rather than read without bound. When the same chunk completed events before it, those are returned first and the next feed or finish raises, so feed an empty chunk to observe it without waiting for more input.

    SseParser::finish

    Ends the stream, discarding any incomplete event; always returns []. Repeated calls are harmless. Raises Protocol if feed left an overflow unreported, so an oversized event at the end is never lost.

    SseParser::new

    fn SseParser::new(max_event_bytes? : Int) -> SseParser

    Creates an empty parser. max_event_bytes bounds one event: the raw bytes of its data lines, of the event and id lines in effect, and of the line being read, line terminators excluded. It defaults to 16 MiB. An event or id line that replaces an earlier one replaces its count too, and the id persists into later events, as the spec says, so it counts against each of them until replaced.

    test {
    let parser = @sse.SseParser::new()
    assert_eq(parser.feed(b"data: hello\n\n")[0].data, "hello")
    assert_eq(parser.finish(), [])
    let _ = @sse.SseParser::new(max_event_bytes=1_048_576)
    }

    each_event

    async fn[E : Error] each_event(stream : &
    BodyStream
    , f : async (SseEvent) -> Unit raise E, max_event_bytes? : Int) -> Unit

    Reads and dispatches events until EOF, always closing the stream on exit. Propagates both stream read errors and callback errors unchanged. An event larger than max_event_bytes (16 MiB by default; see SseParser::new) fails with Protocol after every event before it has been dispatched, without reading further.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io