File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use crate :: Result ;
22use bytes:: Bytes ;
3+ use hyper:: { client:: HttpConnector , Body } ;
34
45const DEFAULT_MAX_RETRIES : usize = 5 ;
6+
57pub struct SyncContext {
68 sync_url : String ,
79 auth_token : Option < String > ,
810 max_retries : usize ,
911 durable_frame_num : u32 ,
12+ client : hyper:: Client < HttpConnector , Body > ,
1013}
1114
1215impl SyncContext {
1316 pub fn new ( sync_url : String , auth_token : Option < String > ) -> Self {
17+ // TODO(lucio): add custom connector + tls support here
18+ let client = hyper:: client:: Client :: builder ( ) . build_http :: < hyper:: Body > ( ) ;
19+
1420 Self {
1521 sync_url,
1622 auth_token,
1723 durable_frame_num : 0 ,
1824 max_retries : DEFAULT_MAX_RETRIES ,
25+ client,
1926 }
2027 }
2128
@@ -40,9 +47,6 @@ impl SyncContext {
4047 async fn push_with_retry ( & self , uri : String , frame : Bytes , max_retries : usize ) -> Result < u32 > {
4148 let mut nr_retries = 0 ;
4249 loop {
43- // TODO(lucio): add custom connector + tls support here
44- let client = hyper:: client:: Client :: builder ( ) . build_http :: < hyper:: Body > ( ) ;
45-
4650 let mut req = http:: Request :: post ( uri. clone ( ) ) ;
4751
4852 match & self . auth_token {
@@ -63,7 +67,7 @@ impl SyncContext {
6367 // from that.
6468 let req = req. body ( frame. clone ( ) . into ( ) ) . expect ( "valid body" ) ;
6569
66- let res = client. request ( req) . await . unwrap ( ) ;
70+ let res = self . client . request ( req) . await . unwrap ( ) ;
6771
6872 // TODO(lucio): only retry on server side errors
6973 if res. status ( ) . is_success ( ) {
You can’t perform that action at this time.
0 commit comments