-
Notifications
You must be signed in to change notification settings - Fork 689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flush don't work #529
Comments
I resolve it |
How to solve the problem? I also encountered the same problem. thanks. |
Sorry, it has been a long time, and I have already forgotten. I find some code block in my project. Maybe it's useful. type WriterFlusher interface {
io.Writer
http.Flusher
}
// wrapperHTTP used to wrap http request for print
func wrapperHTTP(h http.Handler) http.Handler {
slogger := slog.New(slog.NewTextHandler(os.Stdout))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
m := httpsnoop.CaptureMetrics(h, w, r)
defer func() {
slogger.Info("",
"method", r.Method,
"url", r.URL,
"proto", r.Proto,
"user-agent", r.UserAgent(),
"remote", r.RemoteAddr,
"referer", r.Referer(),
"status", m.Code,
"size", m.Written,
"lat-ms", m.Duration.Milliseconds(),
)
}()
})
}
func ListenAndServe(addr string, handler http.Handler) error {
return http.ListenAndServe(addr, wrapperHTTP(handler))
} |
Thanks your reply. But this does not appear to use the flush method. |
I suggest to figure out the actual type of ResponseWriter the server is using (using debbuger or logging). I think your ResponseWriter is not being from Go's default http package. In this package, there is some path that it can wrap default http.ResponseWriter: Lines 263 to 272 in c691c18
It replaces writer to
|
I think adding a Flush method is an easy step to take |
When I try to convert
Response.ResponseWriter
tohttp.Flush
, by usingrestful.Response.ResponseWriter.(http.Flusher)
, it returnfalse
. So, thefunc Flush
faild too.The text was updated successfully, but these errors were encountered: