make hijack more stable (#565)

This commit is contained in:
Kevin Wan
2021-03-15 20:11:09 +08:00
committed by GitHub
parent fcd15c9b17
commit 3c6951577d
6 changed files with 107 additions and 3 deletions

View File

@@ -143,7 +143,11 @@ func (grw *guardedResponseWriter) Header() http.Header {
// Hijack implements the http.Hijacker interface.
// This expands the Response to fulfill http.Hijacker if the underlying http.ResponseWriter supports it.
func (grw *guardedResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return grw.writer.(http.Hijacker).Hijack()
if hijacked, ok := grw.writer.(http.Hijacker); ok {
return hijacked.Hijack()
}
return nil, nil, errors.New("server doesn't support hijacking")
}
func (grw *guardedResponseWriter) Write(body []byte) (int, error) {