Skip to content

Commit

Permalink
use reqwest
Browse files Browse the repository at this point in the history
  • Loading branch information
lz1998 committed Jun 23, 2022
1 parent 66effe1 commit 91331f0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ cached = "0.30"
tracing-subscriber = { version = "0.3", features = ["fmt", "local-time"] }
time = { version = "0.3", features = ["macros", "local-offset"] }
dashmap = "5.2"
hyper = { version = "0.14", features = ["client", "http1"] }
hyper-tls = { version = "0.5", features = ["vendored"] }
reqwest = { version = "0.11", features = ["native-tls-vendored"] }
chrono = "0.4"
xml-rs = "0.8"
async-recursion = "1.0.0"
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub enum RCError {
PB(#[from] prost::DecodeError),
#[error("rq error, {0}")]
RQ(#[from] RQError),
#[error("hyper error, {0}")]
Hyper(#[from] hyper::Error),
#[error("reqwest error, {0}")]
Reqwest(#[from] reqwest::Error),
#[error("base64 decode error, {0}")]
Base64Decode(#[from] base64::DecodeError),
#[error("invalid uri error, {0}")]
Expand Down
16 changes: 10 additions & 6 deletions src/util/uri_reader.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use hyper::{Body, Client, Request};
use std::time::Duration;

use tokio::io::AsyncReadExt;

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

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

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

0 comments on commit 91331f0

Please sign in to comment.