mcp: use http.ResponseController to ensure writes are flushed (#870)
If the ResponseWriter is a wrapped one (which is quite common when using middleware to log things like response sizes), the direct cast to `http.Flusher` doesn't find the flush capability. Instead, use `http.ResponseController` as introduced in go1.20 which handles unwrapping to find the base response writer.
This commit is contained in:
parent
638d404e0d
commit
d3fd25b68a
1 changed files with 10 additions and 9 deletions
|
|
@ -119,14 +119,15 @@ func (s *fakeStreamableServer) ServeHTTP(w http.ResponseWriter, req *http.Reques
|
|||
for k, v := range resp.header {
|
||||
w.Header().Set(k, v)
|
||||
}
|
||||
rc := http.NewResponseController(w)
|
||||
w.WriteHeader(status)
|
||||
w.(http.Flusher).Flush() // flush response headers
|
||||
rc.Flush() // flush response headers
|
||||
|
||||
if v := req.Header.Get(protocolVersionHeader); v != resp.wantProtocolVersion && resp.wantProtocolVersion != "" {
|
||||
s.t.Errorf("%v: bad protocol version header: got %q, want %q", key, v, resp.wantProtocolVersion)
|
||||
}
|
||||
w.Write([]byte(body))
|
||||
w.(http.Flusher).Flush() // flush response
|
||||
rc.Flush() // flush response
|
||||
|
||||
if resp.done != nil {
|
||||
<-resp.done
|
||||
|
|
|
|||
Loading…
Reference in a new issue