From fc45505c46396d741161acce4198bc3120d8562f Mon Sep 17 00:00:00 2001 From: Chan Kang Date: Sun, 19 Jun 2022 15:07:33 -0400 Subject: [PATCH] moving the new error check into existing http response error block to reduce the possibility of false positives --- client.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/client.go b/client.go index a910356..c5c3db0 100644 --- a/client.go +++ b/client.go @@ -186,18 +186,6 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h return nil, nil, errMalformedURL } - if d.TLSClientConfig != nil { - for _, proto := range d.TLSClientConfig.NextProtos { - if proto != "http/1.1" { - return nil, nil, fmt.Errorf( - "websocket: protocol %q was given but is not supported; "+ - "sharing tls.Config with net/http Transport can cause this error", - proto, - ) - } - } - } - req := &http.Request{ Method: http.MethodGet, URL: u, @@ -383,6 +371,17 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h resp, err := http.ReadResponse(conn.br, req) if err != nil { + if d.TLSClientConfig != nil { + for _, proto := range d.TLSClientConfig.NextProtos { + if proto != "http/1.1" { + return nil, nil, fmt.Errorf( + "websocket: protocol %q was given but is not supported; "+ + "sharing tls.Config with net/http Transport can cause this error", + proto, + ) + } + } + } return nil, nil, err }