diff --git a/caddyhttp/header/header.go b/caddyhttp/header/header.go index 121264d4..56595abf 100644 --- a/caddyhttp/header/header.go +++ b/caddyhttp/header/header.go @@ -4,6 +4,9 @@ package header import ( + "bufio" + "errors" + "net" "net/http" "strings" @@ -113,3 +116,12 @@ func (rww *responseWriterWrapper) setHeader(key, value string) { h.Set(key, value) }) } + +// Hijack implements http.Hijacker. It simply wraps the underlying +// ResponseWriter's Hijack method if there is one, or returns an error. +func (rww *responseWriterWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) { + if hj, ok := rww.w.(http.Hijacker); ok { + return hj.Hijack() + } + return nil, nil, errors.New("not a Hijacker") +} diff --git a/caddyhttp/proxy/reverseproxy.go b/caddyhttp/proxy/reverseproxy.go index 1374c08f..1bfbd7e8 100644 --- a/caddyhttp/proxy/reverseproxy.go +++ b/caddyhttp/proxy/reverseproxy.go @@ -189,7 +189,7 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request, res.Body.Close() hj, ok := rw.(http.Hijacker) if !ok { - return nil + panic("not a hijacker") } conn, _, err := hj.Hijack()