11cfg_core ! {
22 use crate :: EncryptionConfig ;
33}
4+
45use crate :: { Database , Result } ;
56
67use super :: DbType ;
@@ -99,6 +100,7 @@ impl Builder<()> {
99100 connector: None ,
100101 version: None ,
101102 } ,
103+ connector: None ,
102104 } ,
103105 }
104106 }
@@ -399,6 +401,7 @@ cfg_sync! {
399401 path: std:: path:: PathBuf ,
400402 flags: crate :: OpenFlags ,
401403 remote: Remote ,
404+ connector: Option <crate :: util:: ConnectorService >,
402405 }
403406
404407 impl Builder <SyncedDatabase > {
@@ -408,6 +411,18 @@ cfg_sync! {
408411 self
409412 }
410413
414+ /// Provide a custom http connector that will be used to create http connections.
415+ pub fn connector<C >( mut self , connector: C ) -> Builder <SyncedDatabase >
416+ where
417+ C : tower:: Service <http:: Uri > + Send + Clone + Sync + ' static ,
418+ C :: Response : crate :: util:: Socket ,
419+ C :: Future : Send + ' static ,
420+ C :: Error : Into <Box <dyn std:: error:: Error + Send + Sync >>,
421+ {
422+ self . inner. connector = Some ( wrap_connector( connector) ) ;
423+ self
424+ }
425+
411426 /// Build a connection to a local database that can be synced to remote server.
412427 pub async fn build( self ) -> Result <Database > {
413428 let SyncedDatabase {
@@ -420,11 +435,16 @@ cfg_sync! {
420435 connector: _,
421436 version: _,
422437 } ,
438+ connector,
423439 } = self . inner;
424440
425441 let path = path. to_str( ) . ok_or( crate :: Error :: InvalidUTF8Path ) ?. to_owned( ) ;
426442
427- let https = super :: connector( ) ?;
443+ let https = if let Some ( connector) = connector {
444+ connector
445+ } else {
446+ wrap_connector( super :: connector( ) ?)
447+ } ;
428448 use tower:: ServiceExt ;
429449
430450 let svc = https
@@ -506,6 +526,22 @@ cfg_remote! {
506526}
507527
508528cfg_replication_or_remote_or_sync ! {
529+ fn wrap_connector<C >( connector: C ) -> crate :: util:: ConnectorService
530+ where
531+ C : tower:: Service <http:: Uri > + Send + Clone + Sync + ' static ,
532+ C :: Response : crate :: util:: Socket ,
533+ C :: Future : Send + ' static ,
534+ C :: Error : Into <Box <dyn std:: error:: Error + Send + Sync >>,
535+ {
536+ use tower:: ServiceExt ;
537+
538+ let svc = connector
539+ . map_err( |e| e. into( ) )
540+ . map_response( |s| Box :: new( s) as Box <dyn crate :: util:: Socket >) ;
541+
542+ crate :: util:: ConnectorService :: new( svc)
543+ }
544+
509545 impl Remote {
510546 fn connector<C >( mut self , connector: C ) -> Remote
511547 where
@@ -514,15 +550,7 @@ cfg_replication_or_remote_or_sync! {
514550 C :: Future : Send + ' static ,
515551 C :: Error : Into <Box <dyn std:: error:: Error + Send + Sync >>,
516552 {
517- use tower:: ServiceExt ;
518-
519- let svc = connector
520- . map_err( |e| e. into( ) )
521- . map_response( |s| Box :: new( s) as Box <dyn crate :: util:: Socket >) ;
522-
523- let svc = crate :: util:: ConnectorService :: new( svc) ;
524-
525- self . connector = Some ( svc) ;
553+ self . connector = Some ( wrap_connector( connector) ) ;
526554 self
527555 }
528556
0 commit comments