Skip to content

Commit

Permalink
Improve error message when proxy connection fails
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
3point2 committed Dec 15, 2022
1 parent b19dc4f commit 674db52
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 674db52

Please sign in to comment.