Skip to content

Commit 0a34dd9

Browse files
Ruslan Babych ⛵️djc
authored andcommitted
fix: can't resolve ip address with square brackets
Problem: Sending to destination like https://[::1]/ fails with error invalid dnsname. Error is thrown here https://github.com/rustls/hyper-rustls/blob/main/src/connector.rs#L95 hyper-rustls resolves the Hostname as hyper::Uri::host This makes hostname = "[::1]" which is HTTP-specific form of writing IPv6 address. Solution: Since square brakets are coming from hyper and not part standard IP notation we remove any square brakets inside of the connector before calling the rustls::ServerName::try_from(hostname)
1 parent 141eb5f commit 0a34dd9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/connector.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,19 @@ where
8585
Box::pin(f)
8686
} else if sch == &http::uri::Scheme::HTTPS {
8787
let cfg = self.tls_config.clone();
88-
let hostname = match self.override_server_name.as_deref() {
88+
let mut hostname = match self.override_server_name.as_deref() {
8989
Some(h) => h,
9090
None => dst.host().unwrap_or_default(),
9191
};
92+
93+
// Remove square brackets around IPv6 address.
94+
if let Some(trimmed) = hostname
95+
.strip_prefix('[')
96+
.and_then(|h| h.strip_suffix(']'))
97+
{
98+
hostname = trimmed;
99+
}
100+
92101
let hostname = match rustls::ServerName::try_from(hostname) {
93102
Ok(dnsname) => dnsname,
94103
Err(_) => {

0 commit comments

Comments
 (0)