fix(api): prevent double logging for streaming responses

This commit is contained in:
hkfires
2025-12-15 18:00:32 +08:00
parent 14aa6cc7e8
commit 97ab623d42

View File

@@ -267,7 +267,7 @@ func (w *ResponseWriterWrapper) Finalize(c *gin.Context) error {
return nil
}
if w.isStreaming {
if w.isStreaming && w.streamWriter != nil {
if w.chunkChannel != nil {
close(w.chunkChannel)
w.chunkChannel = nil
@@ -279,7 +279,6 @@ func (w *ResponseWriterWrapper) Finalize(c *gin.Context) error {
}
// Write API Request and Response to the streaming log before closing
if w.streamWriter != nil {
apiRequest := w.extractAPIRequest(c)
if len(apiRequest) > 0 {
_ = w.streamWriter.WriteAPIRequest(apiRequest)
@@ -293,10 +292,6 @@ func (w *ResponseWriterWrapper) Finalize(c *gin.Context) error {
return err
}
w.streamWriter = nil
}
if forceLog {
return w.logRequest(finalStatusCode, w.cloneHeaders(), w.body.Bytes(), w.extractAPIRequest(c), w.extractAPIResponse(c), slicesAPIResponseError, forceLog)
}
return nil
}