From f38b5b460391bcc582d7ac2201a75691122affd4 Mon Sep 17 00:00:00 2001 From: Jeff Prestes Date: Wed, 25 Mar 2020 06:30:54 -0300 Subject: [PATCH 1/4] add http/2 push support --- response_writer.go | 10 ++++++++++ response_writer_test.go | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/response_writer.go b/response_writer.go index 9133948..3ddda35 100644 --- a/response_writer.go +++ b/response_writer.go @@ -27,6 +27,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. @@ -112,3 +113,12 @@ 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 fmt.Errorf("the ResponseWriter doesn't support the Pusher interface") + } + pusher.Push(target, opts) + return nil +} 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) + }) } From 91f4cdf5dc929c4a3499a01971442d87b1779afb Mon Sep 17 00:00:00 2001 From: Jeff Prestes Date: Thu, 26 Mar 2020 11:32:45 -0300 Subject: [PATCH 2/4] Update method return suggested by unknown at response_writer.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: ᴜɴᴋɴᴡᴏɴ --- response_writer.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/response_writer.go b/response_writer.go index 3ddda35..d7ff768 100644 --- a/response_writer.go +++ b/response_writer.go @@ -119,6 +119,5 @@ func (rw *responseWriter) Push(target string, opts *http.PushOptions) error { if !ok { return fmt.Errorf("the ResponseWriter doesn't support the Pusher interface") } - pusher.Push(target, opts) - return nil + return pusher.Push(target, opts) } From 29660c332881cb9e46a37ca052b409014cd160e3 Mon Sep 17 00:00:00 2001 From: Jeff Prestes Date: Thu, 26 Mar 2020 12:13:45 -0300 Subject: [PATCH 3/4] usage of errors.New --- response_writer.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/response_writer.go b/response_writer.go index d7ff768..498016c 100644 --- a/response_writer.go +++ b/response_writer.go @@ -16,6 +16,7 @@ package macaron import ( "bufio" + "errors" "fmt" "net" "net/http" @@ -117,7 +118,7 @@ func (rw *responseWriter) Flush() { func (rw *responseWriter) Push(target string, opts *http.PushOptions) error { pusher, ok := rw.ResponseWriter.(http.Pusher) if !ok { - return fmt.Errorf("the ResponseWriter doesn't support the Pusher interface") + return errors.New("the ResponseWriter doesn't support the Pusher interface") } return pusher.Push(target, opts) } From efc128962f7cc12677bddc2d004993df392e1335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=9C=C9=B4=E1=B4=8B=C9=B4=E1=B4=A1=E1=B4=8F=C9=B4?= Date: Fri, 27 Mar 2020 00:08:19 +0800 Subject: [PATCH 4/4] Update response_writer.go --- response_writer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/response_writer.go b/response_writer.go index 498016c..59485d4 100644 --- a/response_writer.go +++ b/response_writer.go @@ -93,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() }