7 // ResponseWriter wraps http.ResponseWriter and exposes the status
8 // sent, the number of bytes sent to the client, and the last write
10 type ResponseWriter struct {
12 wroteStatus *int // Last status given to WriteHeader()
13 wroteBodyBytes *int // Bytes successfully written
14 err *error // Last error returned from Write()
17 func WrapResponseWriter(orig http.ResponseWriter) ResponseWriter {
18 return ResponseWriter{orig, new(int), new(int), new(error)}
21 func (w ResponseWriter) WriteHeader(s int) {
23 w.ResponseWriter.WriteHeader(s)
26 func (w ResponseWriter) Write(data []byte) (n int, err error) {
27 n, err = w.ResponseWriter.Write(data)
28 *w.wroteBodyBytes += n
33 func (w ResponseWriter) WroteStatus() int {
37 func (w ResponseWriter) WroteBodyBytes() int {
38 return *w.wroteBodyBytes
41 func (w ResponseWriter) Err() error {