refactor: add set event stream headers func (#402)

封装流式传输响应头的设置
This commit is contained in:
igophper
2023-08-12 21:55:18 +08:00
committed by GitHub
parent 0e9ff8825e
commit ca512f6a38
8 changed files with 16 additions and 35 deletions

View File

@@ -143,11 +143,7 @@ func palmStreamHandler(c *gin.Context, resp *http.Response) (*OpenAIErrorWithSta
dataChan <- string(jsonResponse)
stopChan <- 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")
setEventStreamHeaders(c)
c.Stream(func(w io.Writer) bool {
select {
case data := <-dataChan: