@@ -52,16 +52,17 @@ where
52
52
. unwrap_or ( 5432 ) ;
53
53
54
54
// The value of host is used as the hostname for TLS validation,
55
- // if it's not present, use the value of hostaddr.
56
55
let hostname =match host{
57
- Some ( Host :: Tcp ( host) ) => host. clone ( ) ,
56
+ Some ( Host :: Tcp ( host) ) =>Some ( host. clone ( ) ) ,
58
57
// postgres doesn't support TLS over unix sockets, so the choice here doesn't matter
59
58
#[ cfg( unix) ]
60
- Some ( Host :: Unix ( _) ) =>"" . to_string ( ) ,
61
- None =>hostaddr . map_or ( "" . to_string ( ) , |ipaddr| ipaddr . to_string ( ) ) ,
59
+ Some ( Host :: Unix ( _) ) =>None ,
60
+ None =>None ,
62
61
} ;
63
- let tls = tls
64
- . make_tls_connect ( & hostname)
62
+ let tls = hostname
63
+ . as_ref ( )
64
+ . map ( |s| tls. make_tls_connect ( s) )
65
+ . transpose ( )
65
66
. map_err ( |e|Error :: tls ( e. into ( ) ) ) ?;
66
67
67
68
// Try to use the value of hostaddr to establish the TCP connection,
78
79
}
79
80
} ;
80
81
81
- match connect_once ( & addr, port, tls, config) . await {
82
+ match connect_once ( addr, hostname , port, tls, config) . await {
82
83
Ok ( ( client, connection) ) =>return Ok ( ( client, connection) ) ,
83
84
Err ( e) => error =Some ( e) ,
84
85
}
@@ -88,16 +89,17 @@ where
88
89
}
89
90
90
91
async fn connect_once < T > (
91
- host : & Host ,
92
+ host : Host ,
93
+ hostname : Option < String > ,
92
94
port : u16 ,
93
- tls : T ,
95
+ tls : Option < T > ,
94
96
config : & Config ,
95
97
) ->Result < ( Client , Connection < Socket , T :: Stream > ) , Error >
96
98
where
97
99
T : TlsConnect < Socket > ,
98
100
{
99
101
let socket =connect_socket (
100
- host,
102
+ & host,
101
103
port,
102
104
config. connect_timeout ,
103
105
config. tcp_user_timeout ,
@@ -151,7 +153,8 @@ where
151
153
}
152
154
153
155
client. set_socket_config ( SocketConfig {
154
- host : host. clone ( ) ,
156
+ host,
157
+ hostname,
155
158
port,
156
159
connect_timeout : config. connect_timeout ,
157
160
tcp_user_timeout : config. tcp_user_timeout ,