From c5ea4fde357d8291bd54df2e0f9054c527ee85ef Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 16 Jul 2020 18:16:30 -0300 Subject: [PATCH 1/5] HTTP timeout --- matrix_sdk/src/client.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index af962e7a..b3f6323e 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -105,6 +105,7 @@ pub struct ClientConfig { user_agent: Option, disable_ssl_verification: bool, base_config: BaseClientConfig, + timeout: Duration } // #[cfg_attr(tarpaulin, skip)] @@ -198,6 +199,12 @@ impl ClientConfig { self.base_config = self.base_config.passphrase(passphrase); self } + + /// Set a timeout duration for all HTTP requests. The default is no timeout. + pub fn timeout(mut self, timeout: Duration) -> Self { + self.timeout = timeout; + self + } } #[derive(Debug, Default, Clone)] @@ -298,7 +305,7 @@ impl Client { Err(_e) => panic!("Error parsing homeserver url"), }; - let http_client = reqwest::Client::builder(); + let http_client = reqwest::Client::builder().timeout(config.timeout); #[cfg(not(target_arch = "wasm32"))] let http_client = { From b0241e51a30ce95656ebf6ac2c7e55c65f63a6a5 Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 16 Jul 2020 18:40:52 -0300 Subject: [PATCH 2/5] Fixed formatting --- matrix_sdk/src/client.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index b3f6323e..f811abd9 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -105,7 +105,7 @@ pub struct ClientConfig { user_agent: Option, disable_ssl_verification: bool, base_config: BaseClientConfig, - timeout: Duration + timeout: Duration, } // #[cfg_attr(tarpaulin, skip)] @@ -200,11 +200,11 @@ impl ClientConfig { self } - /// Set a timeout duration for all HTTP requests. The default is no timeout. - pub fn timeout(mut self, timeout: Duration) -> Self { - self.timeout = timeout; - self - } + /// Set a timeout duration for all HTTP requests. The default is no timeout. + pub fn timeout(mut self, timeout: Duration) -> Self { + self.timeout = timeout; + self + } } #[derive(Debug, Default, Clone)] From 2f99d0de59e44b1fcd0bba4850fdd4d543a9c4f2 Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 16 Jul 2020 20:06:26 -0300 Subject: [PATCH 3/5] Bugfix --- matrix_sdk/src/client.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index f811abd9..16e4325c 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -105,7 +105,7 @@ pub struct ClientConfig { user_agent: Option, disable_ssl_verification: bool, base_config: BaseClientConfig, - timeout: Duration, + timeout: Option, } // #[cfg_attr(tarpaulin, skip)] @@ -202,7 +202,7 @@ impl ClientConfig { /// Set a timeout duration for all HTTP requests. The default is no timeout. pub fn timeout(mut self, timeout: Duration) -> Self { - self.timeout = timeout; + self.timeout = Some(timeout); self } } @@ -305,7 +305,12 @@ impl Client { Err(_e) => panic!("Error parsing homeserver url"), }; - let http_client = reqwest::Client::builder().timeout(config.timeout); + let http_client = reqwest::Client::builder(); + + let http_client = match (config.timeout) { + Some(x) => http_client.timeout(x), + None => http_client, + }; #[cfg(not(target_arch = "wasm32"))] let http_client = { From 44dfbd2fa6bbb6507496489ed2a6724f2f1a95b1 Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 16 Jul 2020 20:21:34 -0300 Subject: [PATCH 4/5] Fix --- matrix_sdk/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index 16e4325c..fffed1b4 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -307,7 +307,7 @@ impl Client { let http_client = reqwest::Client::builder(); - let http_client = match (config.timeout) { + let http_client = match config.timeout { Some(x) => http_client.timeout(x), None => http_client, }; From f2163164bfe3eb1952d1b9ae2b534266c1d20e71 Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 16 Jul 2020 20:53:09 -0300 Subject: [PATCH 5/5] Wasm fix --- matrix_sdk/src/client.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index fffed1b4..361bc3a1 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -307,13 +307,13 @@ impl Client { let http_client = reqwest::Client::builder(); - let http_client = match config.timeout { - Some(x) => http_client.timeout(x), - None => http_client, - }; - #[cfg(not(target_arch = "wasm32"))] let http_client = { + let http_client = match config.timeout { + Some(x) => http_client.timeout(x), + None => http_client, + }; + let http_client = if config.disable_ssl_verification { http_client.danger_accept_invalid_certs(true) } else {