x/net/http/httpproxy: misleading error for http requests when proxy URL is misconfigured #64206
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When performing a HTTP request using a proxy URL which is misconfigured, the error message that is returned says:
This error is a bit misleading, and doesn't reveal that the proxy URL is incorrect.
The following program is a minimal test case which reproduces the issue:
And here is a playground link.
In this case, the password contains a character that is not valid (though this URL will work fine in many other non-golang contexts, which makes it even harder to realize that there is something wrong with the URL).
The cause is that the
parseProxy()
function, which, in case of failing to parse the proxy URL, tries to prependhttp://
to the URL and then tries parsing again. This leads to a proxy URL which is parsed with a hostname ofhttp
, which will of course not work.In this case, the URL already has the
http://
prefix, so adding it again will not make it work better (and arguably makes it worse). The logic in theparseProxy()
function could be modified to take this into account.What did you expect to see?
A clearer error message, such as
Proxy URL is misconfigured: net/url: invalid userinfo
would have been clearer and easier to diagnose.What did you see instead?
The error message I get is
Get "https://example.com": proxyconnect tcp: dial tcp: lookup http on 127.0.0.53:53: server misbehaving
, which doesn't reveal the root cause and can lead to confusion.The text was updated successfully, but these errors were encountered: