diff --git a/libsql/src/database/builder.rs b/libsql/src/database/builder.rs index 217443c7d7..f1c60ffb3c 100644 --- a/libsql/src/database/builder.rs +++ b/libsql/src/database/builder.rs @@ -1,6 +1,7 @@ cfg_core! { use crate::EncryptionConfig; } + use crate::{Database, Result}; use super::DbType; @@ -99,6 +100,7 @@ impl Builder<()> { connector: None, version: None, }, + connector:None, }, } } @@ -399,6 +401,7 @@ cfg_sync! { path: std::path::PathBuf, flags: crate::OpenFlags, remote: Remote, + connector: Option, } impl Builder { @@ -408,6 +411,18 @@ cfg_sync! { self } + /// Provide a custom http connector that will be used to create http connections. + pub fn connector(mut self, connector: C) -> Builder + where + C: tower::Service + Send + Clone + Sync + 'static, + C::Response: crate::util::Socket, + C::Future: Send + 'static, + C::Error: Into>, + { + self.inner.connector = Some(wrap_connector(connector)); + self + } + /// Build a connection to a local database that can be synced to remote server. pub async fn build(self) -> Result { let SyncedDatabase { @@ -420,11 +435,16 @@ cfg_sync! { connector: _, version: _, }, + connector, } = self.inner; let path = path.to_str().ok_or(crate::Error::InvalidUTF8Path)?.to_owned(); - let https = super::connector()?; + let https = if let Some(connector) = connector { + connector + } else { + wrap_connector(super::connector()?) + }; use tower::ServiceExt; let svc = https