Add response body size to writer interface

This commit is contained in:
Matt Newberry 2014-09-02 13:17:37 -04:00
parent 3b079bb6f7
commit daedc0bc17

View File

@ -20,6 +20,7 @@ type (
http.CloseNotifier http.CloseNotifier
Status() int Status() int
Size() int
Written() bool Written() bool
WriteHeaderNow() WriteHeaderNow()
} }
@ -27,6 +28,7 @@ type (
responseWriter struct { responseWriter struct {
http.ResponseWriter http.ResponseWriter
status int status int
size int
written bool written bool
} }
) )
@ -55,13 +57,19 @@ func (w *responseWriter) WriteHeaderNow() {
func (w *responseWriter) Write(data []byte) (n int, err error) { func (w *responseWriter) Write(data []byte) (n int, err error) {
w.WriteHeaderNow() w.WriteHeaderNow()
return w.ResponseWriter.Write(data) n, err = w.ResponseWriter.Write(data)
w.size = n
return
} }
func (w *responseWriter) Status() int { func (w *responseWriter) Status() int {
return w.status return w.status
} }
func (w *responseWriter) Size() int {
return w.size
}
func (w *responseWriter) Written() bool { func (w *responseWriter) Written() bool {
return w.written return w.written
} }