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:
@ -113,6 +113,17 @@ func (s *statusRecorder) Write(b []byte) (int, error) {
|
||||
return s.ResponseWriter.Write(b)
|
||||
}
|
||||
|
||||
// Flush forwards to the underlying writer so SSE handlers can stream
|
||||
// incrementally through the access-log wrapper. Without this method the
|
||||
// w.(http.Flusher) assertion inside the streaming chat handlers fails (the
|
||||
// embedded ResponseWriter interface does not carry Flush into the method set),
|
||||
// and every chunk stays buffered until the response ends.
|
||||
func (s *statusRecorder) Flush() {
|
||||
if f, ok := s.ResponseWriter.(http.Flusher); ok {
|
||||
f.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Gateway) routes(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
case r.URL.Path == "/v1/chat/completions":
|
||||
|
||||
Reference in New Issue
Block a user