From e17dc80a9f45278a5e1b220f1b244ccf9f2d1593 Mon Sep 17 00:00:00 2001 From: sigseg5 Date: Mon, 11 Sep 2023 13:40:42 +0400 Subject: [PATCH] Ref optional connection timeout reading logic --- Cargo.toml | 2 +- src/lib.rs | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b387a40..e3c9f31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "outline_api" -version = "1.0.3" +version = "2.0.0" edition = "2021" authors = ["sigseg5"] license = "MIT" diff --git a/src/lib.rs b/src/lib.rs index 6ae8181..19348fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -122,7 +122,7 @@ fn handle_json_api_error(response: Response) -> Result { api_url: &'a str, session: Client, - request_timeout: Duration, + request_timeout: Option, } // Endpoints @@ -147,7 +147,10 @@ impl OutlineVPN<'_> { let response = self .session .request(request_method, &url) - .timeout(self.request_timeout) + .timeout( + self.request_timeout + .unwrap_or_else(|| std::time::Duration::from_secs(REQUEST_TIMEOUT_IN_SEC)), + ) .header(reqwest::header::CONTENT_TYPE, "application/json") .body(request_body) .send()?; @@ -534,16 +537,9 @@ pub fn new<'a>( .build() .unwrap(); - let default_request_timeout = Duration::from_secs(REQUEST_TIMEOUT_IN_SEC); - let safe_request_timeout = if let Some(timeout) = request_timeout { - timeout - } else { - default_request_timeout - }; - OutlineVPN { api_url: &api_url, session, - request_timeout: safe_request_timeout, + request_timeout, } }