improve stream response for http (#2564)

This commit is contained in:
John Guo
2023-04-12 10:12:11 +08:00
committed by GitHub
parent 261672e84c
commit 1aa9f2809e
2 changed files with 6 additions and 3 deletions

View File

@ -95,11 +95,11 @@ func Test_Issue2509(t *testing.T) {
q.Push(1)
q.Push(2)
q.Push(3)
t.Assert(q.Len(), 3)
t.AssertLE(q.Len(), 3)
t.Assert(<-q.C, 1)
t.Assert(q.Len(), 2)
t.AssertLE(q.Len(), 2)
t.Assert(<-q.C, 2)
t.Assert(q.Len(), 1)
t.AssertLE(q.Len(), 1)
t.Assert(<-q.C, 3)
t.Assert(q.Len(), 0)
})

View File

@ -65,5 +65,8 @@ func (w *ResponseWriter) Flush() {
if w.buffer.Len() > 0 {
_, _ = w.writer.Write(w.buffer.Bytes())
w.buffer.Reset()
if flusher, ok := w.RawWriter().(http.Flusher); ok {
flusher.Flush()
}
}
}