Skip to content

Commit

Permalink
Ref optional connection timeout reading logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sigseg5 committed Sep 11, 2023
1 parent 497531b commit e17dc80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "outline_api"
version = "1.0.3"
version = "2.0.0"
edition = "2021"
authors = ["sigseg5"]
license = "MIT"
Expand Down
16 changes: 6 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn handle_json_api_error(response: Response) -> Result<serde_json::Value, String
pub struct OutlineVPN<'a> {
api_url: &'a str,
session: Client,
request_timeout: Duration,
request_timeout: Option<Duration>,
}

// Endpoints
Expand All @@ -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()?;
Expand Down Expand Up @@ -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,
}
}

0 comments on commit e17dc80

Please sign in to comment.