@@ -476,21 +476,40 @@ impl Database {
476476 ) -> Result < u32 > {
477477 let mut nr_retries = 0 ;
478478 loop {
479- let client = reqwest:: Client :: new ( ) ;
480- let mut builder = client. post ( uri. to_owned ( ) ) ;
479+ // TODO(lucio): add custom connector + tls support here
480+ let client = hyper:: client:: Client :: builder ( ) . build_http :: < hyper:: Body > ( ) ;
481+
482+ let mut req = http:: Request :: post ( uri. clone ( ) ) ;
483+
481484 match auth_token {
482485 Some ( ref auth_token) => {
483- builder = builder
484- . header ( "Authorization" , format ! ( "Bearer {}" , auth_token. to_owned( ) ) ) ;
486+ let auth_header =
487+ http:: HeaderValue :: try_from ( format ! ( "Bearer {}" , auth_token. to_owned( ) ) )
488+ . unwrap ( ) ;
489+
490+ req. headers_mut ( )
491+ . expect ( "valid http request" )
492+ . insert ( "Authorization" , auth_header) ;
485493 }
486494 None => { }
487495 }
488- let res = builder. body ( frame. to_vec ( ) ) . send ( ) . await . unwrap ( ) ;
496+
497+ // TODO(lucio): convert this to use bytes to make this clone cheap, it should be
498+ // to possible use BytesMut when reading frames from the WAL and efficiently use Bytes
499+ // from that.
500+ let req = req. body ( frame. clone ( ) . into ( ) ) . expect ( "valid body" ) ;
501+
502+ let res = client. request ( req) . await . unwrap ( ) ;
503+
504+ // TODO(lucio): only retry on server side errors
489505 if res. status ( ) . is_success ( ) {
490- let resp = res. json :: < serde_json:: Value > ( ) . await . unwrap ( ) ;
506+ let res_body = hyper:: body:: to_bytes ( res. into_body ( ) ) . await . unwrap ( ) ;
507+ let resp = serde_json:: from_slice :: < serde_json:: Value > ( & res_body[ ..] ) . unwrap ( ) ;
508+
491509 let max_frame_no = resp. get ( "max_frame_no" ) . unwrap ( ) . as_u64 ( ) . unwrap ( ) ;
492510 return Ok ( max_frame_no as u32 ) ;
493511 }
512+
494513 if nr_retries > max_retries {
495514 return Err ( crate :: errors:: Error :: ConnectionFailed ( format ! (
496515 "Failed to push frame: {}" ,
0 commit comments