@@ -9,10 +9,16 @@ use std::{
99} ;
1010
1111use grpcio:: { Channel , ChannelBuilder , ChannelCredentialsBuilder , Environment } ;
12+ use lazy_static:: * ;
1213use log:: * ;
14+ use regex:: Regex ;
1315
1416use crate :: Result ;
1517
18+ lazy_static ! {
19+ static ref SCHEME_REG : Regex = Regex :: new( r"^\s*(https?://)" ) . unwrap( ) ;
20+ }
21+
1622fn check_pem_file ( tag : & str , path : & Path ) -> Result < File > {
1723 File :: open ( path)
1824 . map_err ( |e| internal_err ! ( "failed to open {} to load {}: {:?}" , path. display( ) , tag, e) )
@@ -65,21 +71,21 @@ impl SecurityManager {
6571 Factory : FnOnce ( Channel ) -> Client ,
6672 {
6773 info ! ( "connect to rpc server at endpoint: {:?}" , addr) ;
68- let addr = addr
69- . trim_start_matches ( "http://" )
70- . trim_start_matches ( "https://" ) ;
74+
75+ let addr = SCHEME_REG . replace ( addr , "" ) ;
76+
7177 let cb = ChannelBuilder :: new ( env)
7278 . keepalive_time ( Duration :: from_secs ( 10 ) )
7379 . keepalive_timeout ( Duration :: from_secs ( 3 ) ) ;
7480
7581 let channel = if self . ca . is_empty ( ) {
76- cb. connect ( addr)
82+ cb. connect ( & addr)
7783 } else {
7884 let cred = ChannelCredentialsBuilder :: new ( )
7985 . root_cert ( self . ca . clone ( ) )
8086 . cert ( self . cert . clone ( ) , load_pem_file ( "private key" , & self . key ) ?)
8187 . build ( ) ;
82- cb. secure_connect ( addr, cred)
88+ cb. secure_connect ( & addr, cred)
8389 } ;
8490
8591 Ok ( factory ( channel) )
0 commit comments