@@ -9,10 +9,16 @@ use std::{
9
9
} ;
10
10
11
11
use grpcio:: { Channel , ChannelBuilder , ChannelCredentialsBuilder , Environment } ;
12
+ use lazy_static:: * ;
12
13
use log:: * ;
14
+ use regex:: Regex ;
13
15
14
16
use crate :: Result ;
15
17
18
+ lazy_static ! {
19
+ static ref SCHEME_REG : Regex = Regex :: new( r"^\s*(https?://)" ) . unwrap( ) ;
20
+ }
21
+
16
22
fn check_pem_file ( tag : & str , path : & Path ) -> Result < File > {
17
23
File :: open ( path)
18
24
. map_err ( |e| internal_err ! ( "failed to open {} to load {}: {:?}" , path. display( ) , tag, e) )
@@ -65,21 +71,21 @@ impl SecurityManager {
65
71
Factory : FnOnce ( Channel ) -> Client ,
66
72
{
67
73
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
+
71
77
let cb = ChannelBuilder :: new ( env)
72
78
. keepalive_time ( Duration :: from_secs ( 10 ) )
73
79
. keepalive_timeout ( Duration :: from_secs ( 3 ) ) ;
74
80
75
81
let channel = if self . ca . is_empty ( ) {
76
- cb. connect ( addr)
82
+ cb. connect ( & addr)
77
83
} else {
78
84
let cred = ChannelCredentialsBuilder :: new ( )
79
85
. root_cert ( self . ca . clone ( ) )
80
86
. cert ( self . cert . clone ( ) , load_pem_file ( "private key" , & self . key ) ?)
81
87
. build ( ) ;
82
- cb. secure_connect ( addr, cred)
88
+ cb. secure_connect ( & addr, cred)
83
89
} ;
84
90
85
91
Ok ( factory ( channel) )
0 commit comments