Skip to content

Commit 9c4f424

Browse files
committed
libsql: add tls hyper support for offline writes
1 parent cf9f513 commit 9c4f424

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

libsql/src/database/builder.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,17 @@ cfg_sync! {
424424

425425
let path = path.to_str().ok_or(crate::Error::InvalidUTF8Path)?.to_owned();
426426

427+
let https = super::connector()?;
428+
use tower::ServiceExt;
429+
430+
let svc = https
431+
.map_err(|e| e.into())
432+
.map_response(|s| Box::new(s) as Box<dyn crate::util::Socket>);
433+
434+
let connector = crate::util::ConnectorService::new(svc);
435+
427436
let db = crate::local::Database::open_local_with_offline_writes(
437+
connector,
428438
path,
429439
flags,
430440
url,

libsql/src/local/database.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ impl Database {
131131
#[cfg(feature = "sync")]
132132
#[doc(hidden)]
133133
pub async fn open_local_with_offline_writes(
134+
connector: crate::util::ConnectorService,
134135
db_path: impl Into<String>,
135136
flags: OpenFlags,
136137
endpoint: String,
@@ -144,6 +145,7 @@ impl Database {
144145
};
145146
let mut db = Database::open(&db_path, flags)?;
146147
db.sync_ctx = Some(tokio::sync::Mutex::new(SyncContext::new(
148+
connector,
147149
endpoint,
148150
Some(auth_token),
149151
)));

libsql/src/sync.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::Result;
1+
use crate::{util::ConnectorService, Result};
22
use bytes::Bytes;
3-
use hyper::{client::HttpConnector, Body};
3+
use hyper::Body;
44

55
const DEFAULT_MAX_RETRIES: usize = 5;
66

@@ -9,13 +9,13 @@ pub struct SyncContext {
99
auth_token: Option<String>,
1010
max_retries: usize,
1111
durable_frame_num: u32,
12-
client: hyper::Client<HttpConnector, Body>,
12+
client: hyper::Client<ConnectorService, Body>,
1313
}
1414

1515
impl SyncContext {
16-
pub fn new(sync_url: String, auth_token: Option<String>) -> Self {
16+
pub fn new(connector: ConnectorService, sync_url: String, auth_token: Option<String>) -> Self {
1717
// TODO(lucio): add custom connector + tls support here
18-
let client = hyper::client::Client::builder().build_http::<hyper::Body>();
18+
let client = hyper::client::Client::builder().build::<_, hyper::Body>(connector);
1919

2020
Self {
2121
sync_url,

0 commit comments

Comments
 (0)