MCPcopy Index your code
hub / github.com/coder/coder / InitiateStream

Method InitiateStream

aibridge/intercept/eventstream/eventstream.go:75–95  ·  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

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

Callers 4

StartMethod · 0.95
ProcessRequestMethod · 0.95

Calls 7

flushFunction · 0.85
DoMethod · 0.65
SetMethod · 0.65
ResetMethod · 0.65
StoreMethod · 0.45
HeaderMethod · 0.45
ErrorMethod · 0.45