mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
refactor: only flush stream response on successful write
This commit is contained in:
@@ -40,9 +40,11 @@ func (rw *ResponseRewriter) Write(data []byte) (int, error) {
|
|||||||
|
|
||||||
if rw.isStreaming {
|
if rw.isStreaming {
|
||||||
n, err := rw.ResponseWriter.Write(rw.rewriteStreamChunk(data))
|
n, err := rw.ResponseWriter.Write(rw.rewriteStreamChunk(data))
|
||||||
|
if err == nil {
|
||||||
if flusher, ok := rw.ResponseWriter.(http.Flusher); ok {
|
if flusher, ok := rw.ResponseWriter.(http.Flusher); ok {
|
||||||
flusher.Flush()
|
flusher.Flush()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
return rw.body.Write(data)
|
return rw.body.Write(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user