Improve error message when proxy connection fails

If the proxy doesn't respond to our CONNECT request with a 2XX status
code, we now display the proxy's response rather than the confusing
error "tls: first record does not look like a TLS handshake"
This commit is contained in:
Vasili Revelas 2022-11-02 21:21:23 +02:00
parent 76fe4039e5
commit 0c74b9e00d

View File

@ -184,12 +184,15 @@ func (s *SpdyRoundTripper) dialWithHttpProxy(req *http.Request, proxyURL *url.UR
//nolint:staticcheck // SA1019 ignore deprecated httputil.NewProxyClientConn
proxyClientConn := httputil.NewProxyClientConn(proxyDialConn, nil)
_, err = proxyClientConn.Do(&proxyReq)
response, err := proxyClientConn.Do(&proxyReq)
//nolint:staticcheck // SA1019 ignore deprecated httputil.ErrPersistEOF: it might be
// returned from the invocation of proxyClientConn.Do
if err != nil && err != httputil.ErrPersistEOF {
return nil, err
}
if response != nil && response.StatusCode >= 300 || response.StatusCode < 200 {
return nil, fmt.Errorf("CONNECT request to %s returned response: %s", proxyURL.Redacted(), response.Status)
}
rwc, _ := proxyClientConn.Hijack()