Repository: go
Issue: x/net/http/httpproxy: misleading error for http requests when proxy URL is misconfigured 
Labels: NeedsInvestigation

<!--
Please answer these questions before submitting your issue. Thanks!
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.21.0 linux/amd64
</pre>

### Does this issue reproduce with the latest release?
Yes

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/pem/.cache/go-build'
GOENV='/home/pem/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/pem/go/bin/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/pem/go/bin/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/pem/git/scribble/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3413766208=/tmp/go-build -gno-record-gcc-switches'
</pre></details>

### What did you do?

When performing a HTTP request using a proxy URL which is misconfigured, the error message that is returned says:
```
Get "https://example.com": proxyconnect tcp: dial tcp: lookup http on 127.0.0.53:53: server misbehaving
```
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:

```
package main

import (
	"fmt"
	"net/http"
	"os"
)

func main() {
	os.Setenv("https_proxy", "http://username:pässword@myproxyserver.com:8080")
	os.Setenv("HTTPS_PROXY", "http://username:pässword@myproxyserver.com:8080")
	_, err := http.Get("https://example.com")
	if err != nil {
		fmt.Println(err.Error())
		return
	}
}
```

And here is a [playground link](https://go.dev/play/p/tI-9EC0P2UR).

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()`](https://github.com/golang/net/blob/fbaf41277f28102c36926d1368dafbe2b54b4c1d/http/httpproxy/proxy.go#L146) function, which, in case of failing to parse the proxy URL, tries to prepend `http://` to the URL and then tries parsing again. This leads to a proxy URL which is parsed with a hostname of `http`, 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 the `parseProxy()` function could be modified to take this into account.

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on go.dev/play is best.
-->

### 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.