diff --git a/relay/helper/common.go b/relay/helper/common.go index 58f555ab..5b3e7674 100644 --- a/relay/helper/common.go +++ b/relay/helper/common.go @@ -15,6 +15,9 @@ import ( ) func FlushWriter(c *gin.Context) error { + if c.Writer == nil { + return nil + } if flusher, ok := c.Writer.(http.Flusher); ok { flusher.Flush() return nil @@ -28,14 +31,14 @@ func SetEventStreamHeaders(c *gin.Context) { return } + // 设置标志,表示头部已经设置过 + c.Set("event_stream_headers_set", true) + c.Writer.Header().Set("Content-Type", "text/event-stream") c.Writer.Header().Set("Cache-Control", "no-cache") c.Writer.Header().Set("Connection", "keep-alive") c.Writer.Header().Set("Transfer-Encoding", "chunked") c.Writer.Header().Set("X-Accel-Buffering", "no") - - // 设置标志,表示头部已经设置过 - c.Set("event_stream_headers_set", true) } func ClaudeData(c *gin.Context, resp dto.ClaudeResponse) error {