implement Flusher and Hijacker for codeCatcher

This commit is contained in:
mpl
2019-09-13 14:32:03 +02:00
committed by Traefiker Bot
parent df5f530058
commit 24d084d7e6

View File

@@ -194,6 +194,21 @@ func (cc *codeCatcher) WriteHeader(code int) {
cc.code = code
}
// Hijack hijacks the connection
func (cc *codeCatcher) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if hj, ok := cc.responseWriter.(http.Hijacker); ok {
return hj.Hijack()
}
return nil, nil, fmt.Errorf("%T is not a http.Hijacker", cc.responseWriter)
}
// Flush sends any buffered data to the client.
func (cc *codeCatcher) Flush() {
if flusher, ok := cc.responseWriter.(http.Flusher); ok {
flusher.Flush()
}
}
type responseRecorder interface {
http.ResponseWriter
http.Flusher