#4661·gin

feat: add InitSSE(), SSEStream() helpers and fix deprecated CloseNotifier in Stream()

Author: shahariazCreated May 22, 2026Updated Jul 25, 2026
Labelstype/proposal

Feature Description

Problem

  1. c.SSEvent / c.Stream require boilerplate SSE headers on every handler.
  2. There is no combined "set up SSE + loop until disconnect" helper.
  3. c.Stream uses the deprecated http.CloseNotifier interface (w.CloseNotify()) which was removed from net/http in Go 1.20+.

Proposed Changes

c.InitSSE() (new)

Sets Content-Type: text/event-stream, Cache-Control: no-cache, Connection: keep-alive and flushes headers immediately — eliminating the copy-paste boilerplate from every SSE handler.

c.SSEStream(step func(*Context) bool) bool (new)

Calls InitSSE(), then loops calling step and flushing after each call. Returns true when the client disconnects (via Request.Context().Done()), false when step returns false. Symmetric with the existing Stream().

c.Stream() fix

Replaces w.CloseNotify() with c.Request.Context().Done() — the modern, non-deprecated way to detect client disconnection.

Alternatives Considered

Users can call c.Render directly, but the ergonomics are poor for the common case. No library-level SSE loop helper currently exists.

Checklist

  • Tests added for all three changes
  • Existing TestContextStream / TestContextStreamWithClientGone updated