From 351b3e8a57c9e0143b7b6f3ed2160dcdce00225e Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Mon, 18 Sep 2023 08:39:19 +0100 Subject: Add connect timeout and overall timeout (#1238) * Add connect timeout and overall timeout * Make it configurable * Fix test * Add docs --- atuin-client/src/api_client.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'atuin-client/src/api_client.rs') diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs index d2ca339f..b6625a34 100644 --- a/atuin-client/src/api_client.rs +++ b/atuin-client/src/api_client.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use std::env; +use std::time::Duration; use eyre::{bail, Result}; use reqwest::{ @@ -106,7 +107,12 @@ pub async fn latest_version() -> Result { } impl<'a> Client<'a> { - pub fn new(sync_addr: &'a str, session_token: &'a str) -> Result { + pub fn new( + sync_addr: &'a str, + session_token: &'a str, + connect_timeout: u64, + timeout: u64, + ) -> Result { let mut headers = HeaderMap::new(); headers.insert(AUTHORIZATION, format!("Token {session_token}").parse()?); @@ -115,6 +121,8 @@ impl<'a> Client<'a> { client: reqwest::Client::builder() .user_agent(APP_USER_AGENT) .default_headers(headers) + .connect_timeout(Duration::new(connect_timeout, 0)) + .timeout(Duration::new(timeout, 0)) .build()?, }) } -- cgit v1.3.1