MCPcopy
hub / github.com/wavetermdev/waveterm / SetupSSE

Method SetupSSE

pkg/web/sse/ssehandler.go:97–131  ·  view source on GitHub ↗

SetupSSE configures the response headers and starts the writer goroutine

()

Source from the content-addressed store, hash-verified

95
96// SetupSSE configures the response headers and starts the writer goroutine
97func (h *SSEHandlerCh) SetupSSE() error {
98 h.lock.Lock()
99 defer h.lock.Unlock()
100
101 if h.closed {
102 return fmt.Errorf("SSE handler is closed")
103 }
104
105 h.initialized = true
106
107 // Reset write deadline for streaming
108 if err := h.rc.SetWriteDeadline(time.Time{}); err != nil {
109 return fmt.Errorf("failed to reset write deadline: %v", err)
110 }
111
112 // Set SSE headers
113 h.w.Header().Set("Content-Type", SSEContentType)
114 h.w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate, no-transform")
115 h.w.Header().Set("Connection", SSEConnection)
116 h.w.Header().Set("x-vercel-ai-ui-message-stream", "v1")
117 h.w.Header().Set("X-Accel-Buffering", "no")
118
119 // Send headers and establish streaming
120 h.w.WriteHeader(http.StatusOK)
121 fmt.Fprint(h.w, SSEStreamStartMsg)
122 if err := h.flush(); err != nil {
123 return err
124 }
125
126 // Start the writer goroutine
127 h.wg.Add(1)
128 go h.writerLoop()
129
130 return nil
131}
132
133// writerLoop handles all writes and keepalives in a single goroutine
134func (h *SSEHandlerCh) writerLoop() {

Callers 4

RunGeminiChatStepFunction · 0.80
RunChatStepFunction · 0.80
RunAnthropicChatStepFunction · 0.80
RunOpenAIChatStepFunction · 0.80

Calls 6

flushMethod · 0.95
writerLoopMethod · 0.95
SetWriteDeadlineMethod · 0.80
SetMethod · 0.45
HeaderMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected