The ResponseWriters defined in rest.handler add Flush interface. (#318)

This commit is contained in:
jichangyun
2020-12-28 21:30:24 +08:00
committed by GitHub
parent 71a2b20301
commit 0bd2a0656c
8 changed files with 88 additions and 0 deletions

View File

@@ -38,6 +38,12 @@ func (w *LoggedResponseWriter) WriteHeader(code int) {
w.code = code
}
func (w *LoggedResponseWriter) Flush() {
if flusher, ok := w.w.(http.Flusher); ok {
flusher.Flush()
}
}
func LogHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
timer := utils.NewElapsedTimer()
@@ -81,6 +87,12 @@ func (w *DetailLoggedResponseWriter) WriteHeader(code int) {
w.writer.WriteHeader(code)
}
func (w *DetailLoggedResponseWriter) Flush() {
if flusher, ok := http.ResponseWriter(w.writer).(http.Flusher); ok {
flusher.Flush()
}
}
func DetailedLogHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
timer := utils.NewElapsedTimer()