File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,6 +45,9 @@ pub struct AsyncClient<S = DefaultSleeper> {
4545 max_retries : usize ,
4646 /// Marker for the type of sleeper used
4747 marker : PhantomData < S > ,
48+ #[ allow( unused) ]
49+ /// HTTP headers to append on every request made to Esplora server.
50+ pub ( crate ) headers : HashMap < String , String > , // TODO: remove this when `bitreq` is implemented
4851}
4952
5053impl < S : Sleeper > AsyncClient < S > {
@@ -62,6 +65,8 @@ impl<S: Sleeper> AsyncClient<S> {
6265 client_builder = client_builder. timeout ( core:: time:: Duration :: from_secs ( timeout) ) ;
6366 }
6467
68+ // TODO: remove this when `bitreq` is implemented
69+ let headers = builder. headers . clone ( ) ;
6570 if !builder. headers . is_empty ( ) {
6671 let mut headers = header:: HeaderMap :: new ( ) ;
6772 for ( k, v) in builder. headers {
@@ -78,6 +83,7 @@ impl<S: Sleeper> AsyncClient<S> {
7883 url : builder. base_url ,
7984 client : client_builder. build ( ) ?,
8085 max_retries : builder. max_retries ,
86+ headers,
8187 marker : PhantomData ,
8288 } )
8389 }
@@ -87,6 +93,7 @@ impl<S: Sleeper> AsyncClient<S> {
8793 AsyncClient {
8894 url,
8995 client,
96+ headers : HashMap :: new ( ) ,
9097 max_retries : crate :: DEFAULT_MAX_RETRIES ,
9198 marker : PhantomData ,
9299 }
Original file line number Diff line number Diff line change @@ -493,6 +493,21 @@ mod test {
493493 ) ;
494494 }
495495
496+ #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
497+ #[ tokio:: test]
498+ async fn test_build_client_with_headers ( ) {
499+ let env = TestEnv :: new ( ) ;
500+ let headers: HashMap < String , String > = [ (
501+ "Authorization" . to_string ( ) ,
502+ "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" . to_string ( ) ,
503+ ) ]
504+ . into ( ) ;
505+ let ( blocking_client, async_client) = env. setup_clients_with_headers ( headers. clone ( ) ) ;
506+
507+ assert_eq ! ( blocking_client. headers, headers) ;
508+ assert_eq ! ( async_client. headers, headers) ;
509+ }
510+
496511 #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
497512 #[ tokio:: test]
498513 async fn test_get_tx ( ) {
You can’t perform that action at this time.
0 commit comments