diff --git a/response_writer.go b/response_writer.go index 9133948..59485d4 100644 --- a/response_writer.go +++ b/response_writer.go @@ -16,6 +16,7 @@ package macaron import ( "bufio" + "errors" "fmt" "net" "net/http" @@ -27,6 +28,7 @@ import ( type ResponseWriter interface { http.ResponseWriter http.Flusher + http.Pusher // Status returns the status code of the response or 0 if the response has not been written. Status() int // Written returns whether or not the ResponseWriter has been written. @@ -91,7 +93,7 @@ func (rw *responseWriter) Before(before BeforeFunc) { func (rw *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { hijacker, ok := rw.ResponseWriter.(http.Hijacker) if !ok { - return nil, nil, fmt.Errorf("the ResponseWriter doesn't support the Hijacker interface") + return nil, nil, errors.New("the ResponseWriter doesn't support the Hijacker interface") } return hijacker.Hijack() } @@ -112,3 +114,11 @@ func (rw *responseWriter) Flush() { flusher.Flush() } } + +func (rw *responseWriter) Push(target string, opts *http.PushOptions) error { + pusher, ok := rw.ResponseWriter.(http.Pusher) + if !ok { + return errors.New("the ResponseWriter doesn't support the Pusher interface") + } + return pusher.Push(target, opts) +} diff --git a/response_writer_test.go b/response_writer_test.go index 082b697..4ce2d11 100644 --- a/response_writer_test.go +++ b/response_writer_test.go @@ -185,4 +185,11 @@ func Test_ResponseWriter(t *testing.T) { So(resp.Code, ShouldEqual, http.StatusOK) So(resp.Body.String(), ShouldEqual, "data: Hello\n\ndata: Hello\n\n") }) + + Convey("Response writer with http/2 push", t, func() { + resp := httptest.NewRecorder() + rw := NewResponseWriter("GET", resp) + _, ok := rw.(http.Pusher) + So(ok, ShouldBeTrue) + }) }