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
1 changed files with 9 additions and 1 deletions

View File

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