Properly wrap http.ResponseWriter
. A simple wrapper around the excellent httpsnoop package that provides slightly better ergonomics.
go get github.com/matthewmueller/httpbuf
func Middleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rw := httpbuf.Wrap(w)
defer rw.Flush()
next.ServeHTTP(rw, r)
fmt.Println("captured", string(rw.Body))
})
}
- Matt Mueller (@mattmueller)
MIT