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

@@ -99,7 +99,11 @@ func (w *cryptionResponseWriter) 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 (w *cryptionResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return w.ResponseWriter.(http.Hijacker).Hijack()
if hijacked, ok := w.ResponseWriter.(http.Hijacker); ok {
return hijacked.Hijack()
}
return nil, nil, errors.New("server doesn't support hijacking")
}
func (w *cryptionResponseWriter) Write(p []byte) (int, error) {