Skip to content

SSE: WHATWG Server-Sent Events parser#10

Merged
OmarAlJarrah merged 4 commits into
mainfrom
feat/sse
Jun 16, 2026
Merged

SSE: WHATWG Server-Sent Events parser#10
OmarAlJarrah merged 4 commits into
mainfrom
feat/sse

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Summary

Implements the sse package: a WHATWG-conformant Server-Sent Events
(text/event-stream) parser that yields events from any io.Reader as a
range-over-func iterator.

What's included

  • sse.EventType (defaults to "message"), Data (multi-line joined with
    \n, trailing newline trimmed), ID (sticky across events per spec), and
    Retry.
  • sse.Parse(r io.Reader) iter.Seq2[Event, error] — runs the WHATWG
    event-stream interpretation algorithm: data/event/id/retry fields
    accumulate and an event dispatches on a blank line. LF and CRLF line endings,
    comment lines (:), one-leading-space stripping, NUL-in-id ignoring, and
    partial-event-discard at EOF are all handled. The scanner buffer is capped at
    1 MiB; an over-long line surfaces bufio.ErrTooLong, and read errors are
    delivered as the iterator's error value.

Behavior changes

None — new package only (sse was a placeholder).

Deferred (not in this PR)

  • The reconnecting connection: Last-Event-ID replay, server retry honoring, and
    reconnect/backoff. The parser is fully usable on its own; reconnection is a
    resilience layer for a follow-up.

Test plan

  • go build ./...
  • go vet ./...
  • gofmt -l . (clean)
  • go test -race ./... (all packages pass)
  • Covered: single/multi-line data, event type, sticky id (incl. NUL-id ignored),
    retry (valid/non-numeric/non-sticky), comments and blank-only input, CRLF,
    leading-space stripping, no-colon field line, partial-event discard at EOF,
    mid-stream read error, over-long line, and early break.

🤖 Generated with Claude Code

OmarAlJarrah and others added 4 commits June 16, 2026 19:21
WHATWG event-stream parser (Event + Parse over io.Reader as iter.Seq2);
reconnecting connection deferred.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@OmarAlJarrah OmarAlJarrah merged commit 7b0e100 into main Jun 16, 2026
1 of 2 checks passed
@OmarAlJarrah OmarAlJarrah deleted the feat/sse branch June 16, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant