Documentation
¶
Overview ¶
Package sse holds server-sent-events helpers for the response path. Today that is exactly one thing: KeepAlive, a response-writer wrapper that emits a caller-supplied no-op frame while the upstream is silent, so byte-watchdog clients — which abort a stream after N seconds without bytes — stay connected through a long prompt-processing or thinking pause.
Deliberately out of scope: parsing, framing or rewriting SSE. KeepAlive never inspects the bytes it forwards beyond checking that the last write ended on a frame boundary.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeepAlive ¶
type KeepAlive struct {
// contains filtered or unexported fields
}
KeepAlive wraps a streaming ResponseWriter and writes frame whenever nothing else has been written for the configured interval. It is an io.Writer + http.Flusher, so the copy loops can write through it unchanged.
Safety of the splice rests on two gates, both required: the ticker only fires when no Write landed in the last interval (so it can never interleave with an in-progress write), and only when the last write ended on an SSE frame boundary (so a copy loop that hands over a half frame — streamCopy reads in 32 KiB blocks, not frames — is never cut in two).
func NewKeepAlive ¶
NewKeepAlive returns a KeepAlive writing frame to w every interval of silence. every <= 0 disables it entirely: Write is a plain pass-through and Start/Stop are no-ops.
func (*KeepAlive) Flush ¶
func (k *KeepAlive) Flush()
Flush satisfies http.Flusher so the wrapped writer keeps flushing per chunk. Writes already flush themselves; this exists for copy loops that flush explicitly.
func (*KeepAlive) Start ¶
Start launches the keepalive goroutine. It exits on ctx cancellation (client gone) or Stop. Call at most once, before the copy loop.