New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/url: mention net.JoinHostPort for constructing url.URL.Host #61093
Comments
is the only difference with net.JoinHostPort the handling of an empty port string? |
No, it has proper handling for IPv6 addresses by wrapping them in a pair of "[" and "]". See RFC 2732, section 3:
|
The net version also does it: https://go.dev/play/p/l0Wu3N4SJWS
|
I had no idea the "net" package has this. I'd be okay downgrading this issue to just documentation in the "url" package to point towards
Edit: I guess, it makes sense to be in "net" since Dial relies on host:port pairs. |
Hello. I came across this documentation issue and I would like to contribute by addressing it. I would be happy to work on this issue and provide a PR. Could you please assign it to me? |
Hi @dsnet! I was looking into issue #61093 regarding the addition detail regarding how
I would like to understand better what specific changes you think are necessary in the net package. Could you please provide more details or point me to the relevant code/documentation that needs attention? |
|
Change https://go.dev/cl/508976 mentions this issue: |
Apparently yes. According to RFC 3986, section 3.2:
which implies that a
where a |
Good to know. But section 3.2.3 does also say
So it would be nice if |
In #16142, we add read support for extracting out the hostname and port.
However, that API is lacking the ability to write a host:port pair. Unfortunately, this is not as trivial as concatenating the host and port with a ":" in-between in the case of IPv6, which requires wrapping the entire host with "[" and "]" characters.
I propose the addition of:
Example outputs:
Considerations:
JoinHostnamePort
instead ofJoinHostPort
to be consistent with theurl.URL.Hostname
method.string
to be consistent withurl.URL.Port
JoinPath
,PathEscape
,PathUnescape
,QueryEscape
,QueryUnescape
.JoinHostnamePort
to return an error, but I personally like the simplicity of an error-less result.\cc @bradfitz
The text was updated successfully, but these errors were encountered: