refactor: only flush stream response on successful write

This commit is contained in:
teeverc
2025-12-13 13:31:34 -08:00
parent 52d5fd1a67
commit cd8c86c6fb

View File

@@ -40,8 +40,10 @@ func (rw *ResponseRewriter) Write(data []byte) (int, error) {
if rw.isStreaming {
n, err := rw.ResponseWriter.Write(rw.rewriteStreamChunk(data))
if flusher, ok := rw.ResponseWriter.(http.Flusher); ok {
flusher.Flush()
if err == nil {
if flusher, ok := rw.ResponseWriter.(http.Flusher); ok {
flusher.Flush()
}
}
return n, err
}