MCPcopy Create free account
hub / github.com/coder/aibridge / InitiateStream

Method InitiateStream

intercept/eventstream/eventstream.go:67–87  ·  view source on GitHub ↗

InitiateStream initiates the SSE stream by sending headers and starting the ping ticker. This is safe to call multiple times as only the first call has any effect.

(w http.ResponseWriter)

Source from the content-addressed store, hash-verified

65// ping ticker. This is safe to call multiple times as only the first call has
66// any effect.
67func (s *EventStream) InitiateStream(w http.ResponseWriter) {
68 s.initiateOnce.Do(func() {
69 s.initiated.Store(true)
70 s.logger.Debug(s.ctx, "stream initiated")
71
72 // Send headers for Server-Sent Event stream.
73 w.Header().Set("Content-Type", "text/event-stream")
74 w.Header().Set("Cache-Control", "no-cache")
75 w.Header().Set("Connection", "keep-alive")
76 w.Header().Set("X-Accel-Buffering", "no")
77
78 // Send initial flush to ensure connection is established.
79 if err := flush(w); err != nil {
80 http.Error(w, err.Error(), http.StatusInternalServerError)
81 return
82 }
83
84 // Start ping ticker.
85 s.tick.Reset(pingInterval)
86 })
87}
88
89// Start handles sending Server-Sent Event to the client.
90func (s *EventStream) Start(w http.ResponseWriter, r *http.Request) {

Callers 2

StartMethod · 0.95
ProcessRequestMethod · 0.95

Calls 3

flushFunction · 0.85
HeaderMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected