moving the new error check into existing http response error block to reduce the possibility of false positives

This commit is contained in:
Chan Kang 2022-06-19 15:07:33 -04:00
parent b67992cf90
commit fc45505c46
1 changed files with 11 additions and 12 deletions

View File

@ -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
}