Skip to content

Commit

Permalink
moving the new error check into existing http response error block to…
Browse files Browse the repository at this point in the history
… reduce the possibility of false positives
  • Loading branch information
Chan Kang committed Jun 21, 2022
1 parent b67992c commit fc45505
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit fc45505

Please sign in to comment.