2015-05-01 04:20:59 +00:00
|
|
|
package recorder
|
2015-04-28 21:42:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ResponseRecorder struct {
|
|
|
|
*httptest.ResponseRecorder
|
|
|
|
}
|
|
|
|
|
2015-05-01 05:18:39 +00:00
|
|
|
func New() *ResponseRecorder {
|
2015-04-28 21:42:09 +00:00
|
|
|
return &ResponseRecorder{httptest.NewRecorder()}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rr *ResponseRecorder) reset() {
|
|
|
|
rr.ResponseRecorder = httptest.NewRecorder()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rr *ResponseRecorder) CloseNotify() <-chan bool {
|
|
|
|
return http.ResponseWriter(rr).(http.CloseNotifier).CloseNotify()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rr *ResponseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
|
|
|
return http.ResponseWriter(rr).(http.Hijacker).Hijack()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rr *ResponseRecorder) Size() int { return rr.Body.Len() }
|
|
|
|
func (rr *ResponseRecorder) Status() int { return rr.Code }
|
|
|
|
func (rr *ResponseRecorder) WriteHeaderNow() {}
|
|
|
|
func (rr *ResponseRecorder) Written() bool { return rr.Code != 0 }
|