From 8904df2753de7ddf87897d454c0baeb1b6f6937c Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 11 Jun 2023 22:36:04 +0800 Subject: [PATCH] feat: update fetch-rs --- __network/fetch-rs/Cargo.toml | 2 +- __network/fetch-rs/src/main.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/__network/fetch-rs/Cargo.toml b/__network/fetch-rs/Cargo.toml index 64507d9..5298eec 100644 --- a/__network/fetch-rs/Cargo.toml +++ b/__network/fetch-rs/Cargo.toml @@ -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" diff --git a/__network/fetch-rs/src/main.rs b/__network/fetch-rs/src/main.rs index 1ab1a5a..4a9e1fb 100644 --- a/__network/fetch-rs/src/main.rs +++ b/__network/fetch-rs/src/main.rs @@ -119,7 +119,7 @@ pub struct FetchOptions { pub method: FetchMethod, pub headers: Vec, pub body: Option>, - // FIXME connect timeout or read timeout? + pub connect_timeout: Option, pub timeout: Option, pub proxy: Option, // TODO hsts supports @@ -172,6 +172,12 @@ pub fn fetch(url: &str, option: &FetchOptions) -> XResult { } } } + 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,