Commit e5d33e73 authored by Tw's avatar Tw

header: implement http.Hijacker for responseWriterWrapper

fix issue #1173
Signed-off-by: default avatarTw <tw19881113@gmail.com>
parent 9ced4b17
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
package header package header
import ( import (
"bufio"
"errors"
"net"
"net/http" "net/http"
"strings" "strings"
...@@ -113,3 +116,12 @@ func (rww *responseWriterWrapper) setHeader(key, value string) { ...@@ -113,3 +116,12 @@ func (rww *responseWriterWrapper) setHeader(key, value string) {
h.Set(key, value) 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")
}
...@@ -189,7 +189,7 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request, ...@@ -189,7 +189,7 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
res.Body.Close() res.Body.Close()
hj, ok := rw.(http.Hijacker) hj, ok := rw.(http.Hijacker)
if !ok { if !ok {
return nil panic("not a hijacker")
} }
conn, _, err := hj.Hijack() conn, _, err := hj.Hijack()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment