@@ -8,7 +8,7 @@ use std::convert::TryFrom;
88use std:: fmt;
99#[ cfg( not( feature = "tokio" ) ) ]
1010use std:: io:: Write ;
11- use std:: net:: ToSocketAddrs ;
11+ use std:: net:: { SocketAddr , ToSocketAddrs } ;
1212use std:: time:: Duration ;
1313
1414#[ cfg( feature = "tokio" ) ]
@@ -97,6 +97,7 @@ impl<'a> std::net::ToSocketAddrs for &'a HttpEndpoint {
9797
9898/// Client for making HTTP requests.
9999pub ( crate ) struct HttpClient {
100+ address : SocketAddr ,
100101 stream : TcpStream ,
101102}
102103
@@ -119,7 +120,7 @@ impl HttpClient {
119120 TcpStream :: from_std ( stream) ?
120121 } ;
121122
122- Ok ( Self { stream } )
123+ Ok ( Self { address , stream } )
123124 }
124125
125126 /// Sends a `GET` request for a resource identified by `uri` at the `host`.
@@ -162,7 +163,6 @@ impl HttpClient {
162163 /// Sends an HTTP request message and reads the response, returning its body. Attempts to
163164 /// reconnect and retry if the connection has been closed.
164165 async fn send_request_with_retry ( & mut self , request : & str ) -> std:: io:: Result < Vec < u8 > > {
165- let endpoint = self . stream . peer_addr ( ) . unwrap ( ) ;
166166 match self . send_request ( request) . await {
167167 Ok ( bytes) => Ok ( bytes) ,
168168 Err ( _) => {
@@ -176,7 +176,7 @@ impl HttpClient {
176176 tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
177177 #[ cfg( not( feature = "tokio" ) ) ]
178178 std:: thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
179- * self = Self :: connect ( endpoint ) ?;
179+ * self = Self :: connect ( self . address ) ?;
180180 self . send_request ( request) . await
181181 } ,
182182 }
0 commit comments