Skip to content

Commit 58149da

Browse files
committed
explicitly handle host being None
1 parent 1a9c1d4 commit 58149da

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tokio-postgres/src/connect.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ where
5151
.copied()
5252
.unwrap_or(5432);
5353

54-
// The value of host is always used as the hostname for TLS validation.
55-
// postgres doesn't support TLS over unix sockets, so the choice for Host::Unix variant here doesn't matter
54+
// The value of host is used as the hostname for TLS validation,
55+
// if it's not present, use the value of hostaddr.
5656
let hostname = match host {
57-
Some(Host::Tcp(host)) => host.as_str(),
58-
_ => "",
57+
Some(Host::Tcp(host)) => host.clone(),
58+
// postgres doesn't support TLS over unix sockets, so the choice here doesn't matter Some()
59+
#[cfg(unix)]
60+
Some(Host::Unix(_)) => "".to_string(),
61+
None => hostaddr.map_or("".to_string(), |ipaddr| ipaddr.to_string()),
5962
};
6063
let tls = tls
61-
.make_tls_connect(hostname)
64+
.make_tls_connect(&hostname)
6265
.map_err(|e| Error::tls(e.into()))?;
6366

6467
// Try to use the value of hostaddr to establish the TCP connection,

0 commit comments

Comments
 (0)