Skip to content

fix(sse): preserve event state and validate streaming responses - #32

Open
rupayon123 wants to merge 9 commits into
kavix:mainfrom
rupayon123:contribution/sse-event-parsing-20260909
Open

rupayon123 wants to merge 9 commits into
kavix:mainfrom
rupayon123:contribution/sse-event-parsing-20260909

Conversation

@rupayon123

@rupayon123 rupayon123 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Problem and change

Bring SSE parsing and streaming behavior in line with event-stream semantics. Preserve empty data fields and persistent event IDs/retry intervals; accept CR, LF, CRLF and a leading UTF-8 BOM; and reject invalid retry values.

The streaming follow-up fixes effective event filtering: untyped events use message, and event names match exactly rather than case-insensitively. Validate the response media type before creating an output log, so an HTML/JSON error response cannot overwrite a prior log. Support data lines smaller than 1 MiB with a documented bounded scanner rather than failing on ordinary 128 KiB payloads.

Custom SSE headers now honor case-insensitive Host overrides through the request host field, and malformed headers are rejected before making a network request.

Validation

  • Parser regressions cover event state, retry fields, delimiters/BOM and 128 KiB/oversized lines.
  • HTTP-server regressions cover filtered/default/case-distinct event types and valid/invalid/missing Content-Type, including preservation of an existing log on rejection.
  • The three September 11 regression groups failed before their fixes. Full env -u NO_COLOR go test ./..., go vet ./..., formatting and diff checks pass after each change.
  • New HTTP-server regressions reproduce the ignored Host override and malformed-header request before the fix. Full Go tests, vet, build, formatting and diff checks pass after the header change. Remote CI for this new head is checked separately; the earlier passing run is not evidence for the new commit.
  • golangci-lint is unavailable locally. No claim of automatic reconnection is made.

Prepared with AI assistance.

@rupayon123 rupayon123 changed the title fix: align sse data state and line parsing with the event-stream format fix(sse): preserve event state and validate streaming responses Sep 11, 2026
@rupayon123

Copy link
Copy Markdown
Contributor Author

Additional fixes pushed to this branch:

  • d750be0: Stop SSE consumption on output write failure.

Full Go tests, go vet and build pass, including a live local streaming server that previously hung after an output failure. The stream now closes promptly and preserves the original write error. A subsequent cleanup separates event formatting from connection lifecycle. Today's changes have no new findings under golangci-lint v2.13.2 using a migrated copy of the repository configuration. This is a scoped lint result: a full CLI-branch scan still reports 93 findings outside today's changes; the legacy v1 linter cannot read the installed Go 1.27 export format.

Prepared with AI assistance. Changes are submitted for review; this is not a claim of maintainer approval.

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