trim [ and ] from host string before used to connect by TcpStream (#1818)

This commit is contained in:
smonv 2022-06-01 08:03:26 +07:00 committed by GitHub
parent c744cb7f60
commit 4e3ff3644f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,10 @@ pub enum Socket {
impl Socket {
pub async fn connect_tcp(host: &str, port: u16) -> io::Result<Self> {
TcpStream::connect((host, port)).await.map(Socket::Tcp)
// Trim square brackets from host if it's an IPv6 address as the `url` crate doesn't do that.
TcpStream::connect((host.trim_matches(|c| c == '[' || c == ']'), port))
.await
.map(Socket::Tcp)
}
#[cfg(unix)]