Skip to content

Commit cf9f513

Browse files
committed
libsql: re-use hyper client for offline sync
1 parent 4fc36f3 commit cf9f513

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

libsql/src/sync.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
use crate::Result;
22
use bytes::Bytes;
3+
use hyper::{client::HttpConnector, Body};
34

45
const DEFAULT_MAX_RETRIES: usize = 5;
6+
57
pub 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

1215
impl 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() {

0 commit comments

Comments
 (0)