0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

header: implement http.Hijacker for responseWriterWrapper

fix issue #1173

Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
Tw 2016-10-10 15:33:36 +08:00
parent 9ced4b17e5
commit e5d33e73f3
2 changed files with 13 additions and 1 deletions

View file

@ -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")
}

View file

@ -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()