Skip to content

Commit 91331f0

Browse files
committed
use reqwest
1 parent 66effe1 commit 91331f0

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ cached = "0.30"
2929
tracing-subscriber = { version = "0.3", features = ["fmt", "local-time"] }
3030
time = { version = "0.3", features = ["macros", "local-offset"] }
3131
dashmap = "5.2"
32-
hyper = { version = "0.14", features = ["client", "http1"] }
33-
hyper-tls = { version = "0.5", features = ["vendored"] }
32+
reqwest = { version = "0.11", features = ["native-tls-vendored"] }
3433
chrono = "0.4"
3534
xml-rs = "0.8"
3635
async-recursion = "1.0.0"

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub enum RCError {
2727
PB(#[from] prost::DecodeError),
2828
#[error("rq error, {0}")]
2929
RQ(#[from] RQError),
30-
#[error("hyper error, {0}")]
31-
Hyper(#[from] hyper::Error),
30+
#[error("reqwest error, {0}")]
31+
Reqwest(#[from] reqwest::Error),
3232
#[error("base64 decode error, {0}")]
3333
Base64Decode(#[from] base64::DecodeError),
3434
#[error("invalid uri error, {0}")]

src/util/uri_reader.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use hyper::{Body, Client, Request};
1+
use std::time::Duration;
2+
23
use tokio::io::AsyncReadExt;
34

45
use crate::error::{RCError, RCResult};
@@ -17,13 +18,16 @@ pub async fn get_binary(uri: &str) -> RCResult<Vec<u8>> {
1718
}
1819

1920
pub async fn http_get(uri: &str) -> RCResult<Vec<u8>> {
20-
let cli = Client::builder().build::<_, Body>(hyper_tls::HttpsConnector::new());
21-
let req = Request::builder().uri(uri).body(Body::empty())?;
22-
let resp = cli.request(req).await?;
23-
hyper::body::to_bytes(resp.into_body())
21+
reqwest::Client::builder()
22+
.timeout(Duration::from_secs(60))
23+
.build()?
24+
.get(uri)
25+
.send()
26+
.await?
27+
.bytes()
2428
.await
2529
.map(|b| b.to_vec())
26-
.map_err(crate::error::RCError::Hyper)
30+
.map_err(RCError::from)
2731
}
2832

2933
pub async fn read_binary_file(path: &str) -> RCResult<Vec<u8>> {

0 commit comments

Comments
 (0)