@@ -32,7 +32,7 @@ impl SyncContext {
32
32
frame_no + 1
33
33
) ;
34
34
let max_frame_no = self
35
- . push_with_retry ( uri, & self . auth_token , frame. to_vec ( ) , self . max_retries )
35
+ . push_with_retry ( uri, frame. to_vec ( ) , self . max_retries )
36
36
. await ?;
37
37
38
38
Ok ( max_frame_no)
@@ -41,46 +41,25 @@ impl SyncContext {
41
41
async fn push_with_retry (
42
42
& self ,
43
43
uri : String ,
44
- auth_token : & Option < String > ,
45
44
frame : Vec < u8 > ,
46
45
max_retries : usize ,
47
46
) -> Result < u32 > {
48
47
let mut nr_retries = 0 ;
49
48
loop {
50
- // TODO(lucio): add custom connector + tls support here
51
- let client = hyper:: client:: Client :: builder ( ) . build_http :: < hyper:: Body > ( ) ;
52
-
53
- let mut req = http:: Request :: post ( uri. clone ( ) ) ;
54
-
55
- match auth_token {
49
+ let client = reqwest:: Client :: new ( ) ;
50
+ let mut builder = client. post ( uri. to_owned ( ) ) ;
51
+ match & self . auth_token {
56
52
Some ( ref auth_token) => {
57
- let auth_header =
58
- http:: HeaderValue :: try_from ( format ! ( "Bearer {}" , auth_token. to_owned( ) ) )
59
- . unwrap ( ) ;
60
-
61
- req. headers_mut ( )
62
- . expect ( "valid http request" )
63
- . insert ( "Authorization" , auth_header) ;
53
+ builder = builder. header ( "Authorization" , format ! ( "Bearer {}" , auth_token) ) ;
64
54
}
65
55
None => { }
66
56
}
67
-
68
- // TODO(lucio): convert this to use bytes to make this clone cheap, it should be
69
- // to possible use BytesMut when reading frames from the WAL and efficiently use Bytes
70
- // from that.
71
- let req = req. body ( frame. clone ( ) . into ( ) ) . expect ( "valid body" ) ;
72
-
73
- let res = client. request ( req) . await . unwrap ( ) ;
74
-
75
- // TODO(lucio): only retry on server side errors
57
+ let res = builder. body ( frame. to_vec ( ) ) . send ( ) . await . unwrap ( ) ;
76
58
if res. status ( ) . is_success ( ) {
77
- let res_body = hyper:: body:: to_bytes ( res. into_body ( ) ) . await . unwrap ( ) ;
78
- let resp = serde_json:: from_slice :: < serde_json:: Value > ( & res_body[ ..] ) . unwrap ( ) ;
79
-
59
+ let resp = res. json :: < serde_json:: Value > ( ) . await . unwrap ( ) ;
80
60
let max_frame_no = resp. get ( "max_frame_no" ) . unwrap ( ) . as_u64 ( ) . unwrap ( ) ;
81
61
return Ok ( max_frame_no as u32 ) ;
82
62
}
83
-
84
63
if nr_retries > max_retries {
85
64
return Err ( crate :: errors:: Error :: ConnectionFailed ( format ! (
86
65
"Failed to push frame: {}" ,
0 commit comments