mirror of
https://github.com/labstack/echo.git
synced 2024-11-24 08:22:21 +02:00
42 lines
896 B
Go
42 lines
896 B
Go
|
//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)
|
||
|
}
|
||
|
}
|
||
|
}
|