From 7a53991bd6200b875e492d9c3f8e99a9a0c11056 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Tue, 25 Jul 2017 22:46:41 -0700 Subject: [PATCH] Fix panic in hijack Signed-off-by: Tibor Vass --- client/hijack.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/client/hijack.go b/client/hijack.go index 346c74ae82..8cf0119f3d 100644 --- a/client/hijack.go +++ b/client/hijack.go @@ -177,12 +177,14 @@ func (cli *Client) setupHijackConn(req *http.Request, proto string) (net.Conn, e // Server hijacks the connection, error 'connection closed' expected resp, err := clientconn.Do(req) - if err != nil { - return nil, err - } - if resp.StatusCode != http.StatusSwitchingProtocols { - resp.Body.Close() - return nil, fmt.Errorf("unable to upgrade to %s, received %d", proto, resp.StatusCode) + if err != httputil.ErrPersistEOF { + if err != nil { + return nil, err + } + if resp.StatusCode != http.StatusSwitchingProtocols { + resp.Body.Close() + return nil, fmt.Errorf("unable to upgrade to %s, received %d", proto, resp.StatusCode) + } } c, br := clientconn.Hijack()