diff --git a/response_recorder.go b/response_recorder.go index b8b1e21..8030b62 100644 --- a/response_recorder.go +++ b/response_recorder.go @@ -5,7 +5,13 @@ package web -import "net/http" +import ( + "bufio" + "errors" + "io" + "net" + "net/http" +) // ResponseStatusRecorder implements http.ResponseWriter that keeps tack of HTTP // response status code and written body size in bytes. @@ -56,3 +62,35 @@ func (r *ResponseStatusRecorder) Status() int { func (r *ResponseStatusRecorder) ResponseBodySize() int { return r.size } + +func (r *ResponseStatusRecorder) Flush() { + f, ok := r.ResponseWriter.(http.Flusher) + if !ok { + return + } + f.Flush() +} + +func (r *ResponseStatusRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) { + h, ok := r.ResponseWriter.(http.Hijacker) + if !ok { + return nil, nil, errors.New("response writer does not implement http.Hijacker") + } + return h.Hijack() +} + +func (r *ResponseStatusRecorder) ReadFrom(src io.Reader) (int64, error) { + rf, ok := r.ResponseWriter.(io.ReaderFrom) + if !ok { + return 0, errors.New("response writer does not implement io.ReaderFrom") + } + return rf.ReadFrom(src) +} + +func (r *ResponseStatusRecorder) Push(target string, opts *http.PushOptions) error { + p, ok := r.ResponseWriter.(http.Pusher) + if !ok { + return errors.New("response writer does not implement http.Pusher") + } + return p.Push(target, opts) +}