mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-09-20 08:57:57 +00:00
fix(gateway): forward Flush through statusRecorder so SSE streams in real time
statusRecorder (the access-log wrapper) did not implement http.Flusher, so w.(http.Flusher) inside streamChat/streamChatAuto returned nil and every SSE chunk stayed buffered until the response ended. Add Flush() that delegates to the underlying writer when it supports flushing. Regression test: TestStatusRecorderFlusher pins the interface assertion and the forwarding path.
This commit is contained in:
@ -671,3 +671,34 @@ func TestHasScopeModelWithSourcePrefix(t *testing.T) {
|
||||
t.Error("AUTO scope should allow any prefixed model")
|
||||
}
|
||||
}
|
||||
|
||||
// TestStatusRecorderFlusher pins the SSE-critical contract: the access-log
|
||||
// wrapper must implement http.Flusher, otherwise the streaming chat handlers'
|
||||
// w.(http.Flusher) assertion yields nil and chunks are never flushed until
|
||||
// the response ends (regression for the buffered-SSE bug).
|
||||
func TestStatusRecorderFlusher(t *testing.T) {
|
||||
var inner *flushRecorder
|
||||
rr := httptest.NewRecorder()
|
||||
inner = &flushRecorder{ResponseWriter: rr}
|
||||
sr := &statusRecorder{ResponseWriter: inner}
|
||||
|
||||
fl, ok := any(sr).(http.Flusher)
|
||||
if !ok {
|
||||
t.Fatal("statusRecorder does not implement http.Flusher — SSE streaming is broken")
|
||||
}
|
||||
if inner.flushed {
|
||||
t.Fatal("Flush called before Flush()")
|
||||
}
|
||||
fl.Flush()
|
||||
if !inner.flushed {
|
||||
t.Fatal("statusRecorder.Flush did not forward to the underlying writer")
|
||||
}
|
||||
}
|
||||
|
||||
// flushRecorder records whether Flush was forwarded.
|
||||
type flushRecorder struct {
|
||||
http.ResponseWriter
|
||||
flushed bool
|
||||
}
|
||||
|
||||
func (f *flushRecorder) Flush() { f.flushed = true }
|
||||
|
||||
Reference in New Issue
Block a user