mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-19 04:40:52 +08:00
fix(api): prevent double logging for streaming responses
This commit is contained in:
@@ -267,7 +267,7 @@ func (w *ResponseWriterWrapper) Finalize(c *gin.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.isStreaming {
|
if w.isStreaming && w.streamWriter != nil {
|
||||||
if w.chunkChannel != nil {
|
if w.chunkChannel != nil {
|
||||||
close(w.chunkChannel)
|
close(w.chunkChannel)
|
||||||
w.chunkChannel = nil
|
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
|
// Write API Request and Response to the streaming log before closing
|
||||||
if w.streamWriter != nil {
|
|
||||||
apiRequest := w.extractAPIRequest(c)
|
apiRequest := w.extractAPIRequest(c)
|
||||||
if len(apiRequest) > 0 {
|
if len(apiRequest) > 0 {
|
||||||
_ = w.streamWriter.WriteAPIRequest(apiRequest)
|
_ = w.streamWriter.WriteAPIRequest(apiRequest)
|
||||||
@@ -293,10 +292,6 @@ func (w *ResponseWriterWrapper) Finalize(c *gin.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.streamWriter = nil
|
w.streamWriter = nil
|
||||||
}
|
|
||||||
if forceLog {
|
|
||||||
return w.logRequest(finalStatusCode, w.cloneHeaders(), w.body.Bytes(), w.extractAPIRequest(c), w.extractAPIResponse(c), slicesAPIResponseError, forceLog)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user