@@ -8,7 +8,7 @@ use std::convert::TryFrom;
8
8
use std:: fmt;
9
9
#[ cfg( not( feature = "tokio" ) ) ]
10
10
use std:: io:: Write ;
11
- use std:: net:: ToSocketAddrs ;
11
+ use std:: net:: { SocketAddr , ToSocketAddrs } ;
12
12
use std:: time:: Duration ;
13
13
14
14
#[ cfg( feature = "tokio" ) ]
@@ -97,6 +97,7 @@ impl<'a> std::net::ToSocketAddrs for &'a HttpEndpoint {
97
97
98
98
/// Client for making HTTP requests.
99
99
pub ( crate ) struct HttpClient {
100
+ address : SocketAddr ,
100
101
stream : TcpStream ,
101
102
}
102
103
@@ -119,7 +120,7 @@ impl HttpClient {
119
120
TcpStream :: from_std ( stream) ?
120
121
} ;
121
122
122
- Ok ( Self { stream } )
123
+ Ok ( Self { address , stream } )
123
124
}
124
125
125
126
/// Sends a `GET` request for a resource identified by `uri` at the `host`.
@@ -162,7 +163,6 @@ impl HttpClient {
162
163
/// Sends an HTTP request message and reads the response, returning its body. Attempts to
163
164
/// reconnect and retry if the connection has been closed.
164
165
async fn send_request_with_retry ( & mut self , request : & str ) -> std:: io:: Result < Vec < u8 > > {
165
- let endpoint = self . stream . peer_addr ( ) . unwrap ( ) ;
166
166
match self . send_request ( request) . await {
167
167
Ok ( bytes) => Ok ( bytes) ,
168
168
Err ( _) => {
@@ -176,7 +176,7 @@ impl HttpClient {
176
176
tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
177
177
#[ cfg( not( feature = "tokio" ) ) ]
178
178
std:: thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
179
- * self = Self :: connect ( endpoint ) ?;
179
+ * self = Self :: connect ( self . address ) ?;
180
180
self . send_request ( request) . await
181
181
} ,
182
182
}
0 commit comments