File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: Result ;
2
2
use bytes:: Bytes ;
3
+ use hyper:: { client:: HttpConnector , Body } ;
3
4
4
5
const DEFAULT_MAX_RETRIES : usize = 5 ;
6
+
5
7
pub struct SyncContext {
6
8
sync_url : String ,
7
9
auth_token : Option < String > ,
8
10
max_retries : usize ,
9
11
durable_frame_num : u32 ,
12
+ client : hyper:: Client < HttpConnector , Body > ,
10
13
}
11
14
12
15
impl SyncContext {
13
16
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
+
14
20
Self {
15
21
sync_url,
16
22
auth_token,
17
23
durable_frame_num : 0 ,
18
24
max_retries : DEFAULT_MAX_RETRIES ,
25
+ client,
19
26
}
20
27
}
21
28
@@ -40,9 +47,6 @@ impl SyncContext {
40
47
async fn push_with_retry ( & self , uri : String , frame : Bytes , max_retries : usize ) -> Result < u32 > {
41
48
let mut nr_retries = 0 ;
42
49
loop {
43
- // TODO(lucio): add custom connector + tls support here
44
- let client = hyper:: client:: Client :: builder ( ) . build_http :: < hyper:: Body > ( ) ;
45
-
46
50
let mut req = http:: Request :: post ( uri. clone ( ) ) ;
47
51
48
52
match & self . auth_token {
@@ -63,7 +67,7 @@ impl SyncContext {
63
67
// from that.
64
68
let req = req. body ( frame. clone ( ) . into ( ) ) . expect ( "valid body" ) ;
65
69
66
- let res = client. request ( req) . await . unwrap ( ) ;
70
+ let res = self . client . request ( req) . await . unwrap ( ) ;
67
71
68
72
// TODO(lucio): only retry on server side errors
69
73
if res. status ( ) . is_success ( ) {
You can’t perform that action at this time.
0 commit comments