mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00: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,24 +279,19 @@ 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)
|
}
|
||||||
}
|
apiResponse := w.extractAPIResponse(c)
|
||||||
apiResponse := w.extractAPIResponse(c)
|
if len(apiResponse) > 0 {
|
||||||
if len(apiResponse) > 0 {
|
_ = w.streamWriter.WriteAPIResponse(apiResponse)
|
||||||
_ = w.streamWriter.WriteAPIResponse(apiResponse)
|
}
|
||||||
}
|
if err := w.streamWriter.Close(); err != nil {
|
||||||
if err := w.streamWriter.Close(); err != nil {
|
|
||||||
w.streamWriter = nil
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.streamWriter = nil
|
w.streamWriter = nil
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
if forceLog {
|
w.streamWriter = nil
|
||||||
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