Feature Description
Problem
c.SSEvent / c.Stream require boilerplate SSE headers on every handler.
- There is no combined "set up SSE + loop until disconnect" helper.
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
Feature Description
Problem
c.SSEvent/c.Streamrequire boilerplate SSE headers on every handler.c.Streamuses the deprecatedhttp.CloseNotifierinterface(
w.CloseNotify()) which was removed fromnet/httpin Go 1.20+.Proposed Changes
c.InitSSE()(new)Sets
Content-Type: text/event-stream,Cache-Control: no-cache,Connection: keep-aliveand flushes headers immediately — eliminatingthe copy-paste boilerplate from every SSE handler.
c.SSEStream(step func(*Context) bool) bool(new)Calls
InitSSE(), then loops callingstepand flushing after each call.Returns
truewhen the client disconnects (viaRequest.Context().Done()),falsewhenstepreturns false. Symmetric with the existingStream().c.Stream()fixReplaces
w.CloseNotify()withc.Request.Context().Done()— the modern,non-deprecated way to detect client disconnection.
Alternatives Considered
Users can call
c.Renderdirectly, but the ergonomics are poor for thecommon case. No library-level SSE loop helper currently exists.
Checklist
TestContextStream/TestContextStreamWithClientGoneupdated