title: How to dump both HTTP request and response in golang
body: <p>I'm using gorilla web tool kit. There's a <a href="http://www.gorillatoolkit.org/pkg/handlers#LoggingHandler" rel="nofollow">LoggingHandler</a> available in the handler package, however it can only log the request data via the handler.</p>
  
  <pre><code>r := mux.NewRouter()
  r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
      w.Write([]byte("This is a catch-all route"))
  })
  // This can only log the request, how can we log the response?
  loggedRouter := handlers.LoggingHandler(os.Stdout, r) 
  http.ListenAndServe(":1123", loggedRouter)
  </code></pre>
  
  <p><a href="https://golang.org/pkg/net/http/httputil/#DumpRequest" rel="nofollow">httputil</a> has the same feature available via DumpRequest(). In my case client is a browser, and I'm looking for a handler approach to log the response rather than logging it inside each and every handler.</p>