feat: update fetch-rs

This commit is contained in:
2023-06-11 22:36:04 +08:00
parent 49fefb745c
commit 8904df2753
2 changed files with 8 additions and 2 deletions

View File

@@ -6,5 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "0.11.18", features = ["blocking", "rustls-tls"] }
reqwest = { version = "0.11.18", features = ["blocking", "rustls-tls", "native-tls"] }
rust_util = "0.6.41"

View File

@@ -119,7 +119,7 @@ pub struct FetchOptions {
pub method: FetchMethod,
pub headers: Vec<FetchHeader>,
pub body: Option<Vec<u8>>,
// FIXME connect timeout or read timeout?
pub connect_timeout: Option<Duration>,
pub timeout: Option<Duration>,
pub proxy: Option<String>,
// TODO hsts supports
@@ -172,6 +172,12 @@ pub fn fetch(url: &str, option: &FetchOptions) -> XResult<FetchResponse> {
}
}
}
let connect_timeout = match &option.connect_timeout {
Some(connect_timeout) => connect_timeout.to_owned(),
None => Duration::from_secs(5),
};
client_builder = client_builder.connect_timeout(connect_timeout);
// client_builder = client_builder.timeout(Duration::from_secs(50));
let client = client_builder.build()?;
let method = match option.method {
FetchMethod::Get => Method::GET,