Skip to content

Commit 05c3dcf

Browse files
author
dengjie
committed
rpc: user regexp replace string match scheme
Signed-off-by: dengjie <dengjie.hello2dj@bytedance.com>
1 parent f4a1ccf commit 05c3dcf

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ integration-tests = []
1818
name = "tikv_client"
1919

2020
[dependencies]
21+
regex = "1"
2122
failure = "0.1"
2223
futures = "0.1"
2324
fxhash = "0.2"

src/rpc/security.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ use std::{
66
path::{Path, PathBuf},
77
sync::Arc,
88
time::Duration,
9+
borrow::Borrow,
910
};
1011

1112
use grpcio::{Channel, ChannelBuilder, ChannelCredentialsBuilder, Environment};
1213
use log::*;
14+
use lazy_static::*;
15+
use regex::Regex;
1316

1417
use crate::Result;
1518

19+
lazy_static! {
20+
static ref SCHEME_REG: Regex = Regex::new(r"^\s*(https?://)").unwrap();
21+
}
22+
23+
1624
fn check_pem_file(tag: &str, path: &Path) -> Result<File> {
1725
File::open(path)
1826
.map_err(|e| internal_err!("failed to open {} to load {}: {:?}", path.display(), tag, e))
@@ -65,9 +73,10 @@ impl SecurityManager {
6573
Factory: FnOnce(Channel) -> Client,
6674
{
6775
info!("connect to rpc server at endpoint: {:?}", addr);
68-
let addr = addr
69-
.trim_start_matches("http://")
70-
.trim_start_matches("https://");
76+
77+
let cow_addr = SCHEME_REG.replace(addr, "");
78+
let addr: &str = cow_addr.borrow();
79+
7180
let cb = ChannelBuilder::new(env)
7281
.keepalive_time(Duration::from_secs(10))
7382
.keepalive_timeout(Duration::from_secs(3));

0 commit comments

Comments
 (0)