diff --git a/middleware/body_dump.go b/middleware/body_dump.go index b06f76202..e4119ec1e 100644 --- a/middleware/body_dump.go +++ b/middleware/body_dump.go @@ -98,14 +98,14 @@ func (w *bodyDumpResponseWriter) Write(b []byte) (int, error) { } func (w *bodyDumpResponseWriter) Flush() { - err := responseControllerFlush(w.ResponseWriter) + err := http.NewResponseController(w.ResponseWriter).Flush() if err != nil && errors.Is(err, http.ErrNotSupported) { panic(errors.New("response writer flushing is not supported")) } } func (w *bodyDumpResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { - return responseControllerHijack(w.ResponseWriter) + return http.NewResponseController(w.ResponseWriter).Hijack() } func (w *bodyDumpResponseWriter) Unwrap() http.ResponseWriter { diff --git a/middleware/compress.go b/middleware/compress.go index 557bdc8e2..012b76b01 100644 --- a/middleware/compress.go +++ b/middleware/compress.go @@ -190,7 +190,7 @@ func (w *gzipResponseWriter) Flush() { } w.Writer.(*gzip.Writer).Flush() - _ = responseControllerFlush(w.ResponseWriter) + _ = http.NewResponseController(w.ResponseWriter).Flush() } func (w *gzipResponseWriter) Unwrap() http.ResponseWriter { @@ -198,7 +198,7 @@ func (w *gzipResponseWriter) Unwrap() http.ResponseWriter { } func (w *gzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { - return responseControllerHijack(w.ResponseWriter) + return http.NewResponseController(w.ResponseWriter).Hijack() } func (w *gzipResponseWriter) Push(target string, opts *http.PushOptions) error { diff --git a/middleware/responsecontroller_1.19.go b/middleware/responsecontroller_1.19.go deleted file mode 100644 index ddf6b64c0..000000000 --- a/middleware/responsecontroller_1.19.go +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors - -//go:build !go1.20 - -package middleware - -import ( - "bufio" - "fmt" - "net" - "net/http" -) - -// TODO: remove when Go 1.23 is released and we do not support 1.19 anymore -func responseControllerFlush(rw http.ResponseWriter) error { - for { - switch t := rw.(type) { - case interface{ FlushError() error }: - return t.FlushError() - case http.Flusher: - t.Flush() - return nil - case interface{ Unwrap() http.ResponseWriter }: - rw = t.Unwrap() - default: - return fmt.Errorf("%w", http.ErrNotSupported) - } - } -} - -// TODO: remove when Go 1.23 is released and we do not support 1.19 anymore -func responseControllerHijack(rw http.ResponseWriter) (net.Conn, *bufio.ReadWriter, error) { - for { - switch t := rw.(type) { - case http.Hijacker: - return t.Hijack() - case interface{ Unwrap() http.ResponseWriter }: - rw = t.Unwrap() - default: - return nil, nil, fmt.Errorf("%w", http.ErrNotSupported) - } - } -} diff --git a/middleware/responsecontroller_1.20.go b/middleware/responsecontroller_1.20.go deleted file mode 100644 index bc03059bc..000000000 --- a/middleware/responsecontroller_1.20.go +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors - -//go:build go1.20 - -package middleware - -import ( - "bufio" - "net" - "net/http" -) - -func responseControllerFlush(rw http.ResponseWriter) error { - return http.NewResponseController(rw).Flush() -} - -func responseControllerHijack(rw http.ResponseWriter) (net.Conn, *bufio.ReadWriter, error) { - return http.NewResponseController(rw).Hijack() -} diff --git a/response.go b/response.go index a40072dc2..0f174536d 100644 --- a/response.go +++ b/response.go @@ -86,7 +86,7 @@ func (r *Response) Write(b []byte) (n int, err error) { // buffered data to the client. // See [http.Flusher](https://golang.org/pkg/net/http/#Flusher) func (r *Response) Flush() { - err := responseControllerFlush(r.Writer) + err := http.NewResponseController(r.Writer).Flush() if err != nil && errors.Is(err, http.ErrNotSupported) { panic(errors.New("response writer flushing is not supported")) } @@ -96,7 +96,7 @@ func (r *Response) Flush() { // take over the connection. // See [http.Hijacker](https://golang.org/pkg/net/http/#Hijacker) func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error) { - return responseControllerHijack(r.Writer) + return http.NewResponseController(r.Writer).Hijack() } // Unwrap returns the original http.ResponseWriter. diff --git a/responsecontroller_1.19.go b/responsecontroller_1.19.go deleted file mode 100644 index 782dab3a3..000000000 --- a/responsecontroller_1.19.go +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors - -//go:build !go1.20 - -package echo - -import ( - "bufio" - "fmt" - "net" - "net/http" -) - -// TODO: remove when Go 1.23 is released and we do not support 1.19 anymore -func responseControllerFlush(rw http.ResponseWriter) error { - for { - switch t := rw.(type) { - case interface{ FlushError() error }: - return t.FlushError() - case http.Flusher: - t.Flush() - return nil - case interface{ Unwrap() http.ResponseWriter }: - rw = t.Unwrap() - default: - return fmt.Errorf("%w", http.ErrNotSupported) - } - } -} - -// TODO: remove when Go 1.23 is released and we do not support 1.19 anymore -func responseControllerHijack(rw http.ResponseWriter) (net.Conn, *bufio.ReadWriter, error) { - for { - switch t := rw.(type) { - case http.Hijacker: - return t.Hijack() - case interface{ Unwrap() http.ResponseWriter }: - rw = t.Unwrap() - default: - return nil, nil, fmt.Errorf("%w", http.ErrNotSupported) - } - } -} diff --git a/responsecontroller_1.20.go b/responsecontroller_1.20.go deleted file mode 100644 index 6d77c07f8..000000000 --- a/responsecontroller_1.20.go +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors - -//go:build go1.20 - -package echo - -import ( - "bufio" - "net" - "net/http" -) - -func responseControllerFlush(rw http.ResponseWriter) error { - return http.NewResponseController(rw).Flush() -} - -func responseControllerHijack(rw http.ResponseWriter) (net.Conn, *bufio.ReadWriter, error) { - return http.NewResponseController(rw).Hijack() -}