mcp: use http.ResponseController to ensure writes are flushed#870
Conversation
|
This assumes that the wrapper implements |
The wrapper can implement It seems like it is still not as well known as it should be, but it isn't uncommon:
Note that several of these also implement An additional change I plan to propose (in a future PR) is also calling func DisableWriteDeadlineMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rc := http.NewResponseController(w)
if err := rc.SetWriteDeadline(time.Time{}); err != nil {
logging.ContextLogger(r.Context()).Warn("unable to disable write deadline", zap.Error(err))
}
next.ServeHTTP(w, r)
})
} |
maciej-kisiel
left a comment
There was a problem hiding this comment.
Please merge main.
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.
8d30ffe to
5be9a54
Compare
|
Added the suggested comments and rebased on main. |
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.Flusherdoesn't find the flush capability. Instead, usehttp.ResponseControlleras introduced in go1.20 which handles unwrapping to find the base response writer.