From 617c14c22592d784f1d90c6a7e493cba374bf42d Mon Sep 17 00:00:00 2001 From: bylerbk Date: Tue, 1 Oct 2024 22:25:10 -0400 Subject: [PATCH 1/3] Allowing users of the library to tweak the reqwest client's timeout --- thirtyfour/src/common/config.rs | 13 +++++++++++++ thirtyfour/src/web_driver.rs | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/thirtyfour/src/common/config.rs b/thirtyfour/src/common/config.rs index 898817d..c50d4d9 100644 --- a/thirtyfour/src/common/config.rs +++ b/thirtyfour/src/common/config.rs @@ -6,6 +6,7 @@ use crate::{ use const_format::formatcp; use http::HeaderValue; use std::sync::Arc; +use std::time::Duration; /// Configuration options used by a `WebDriver` instance and the related `SessionHandle`. /// @@ -19,6 +20,8 @@ pub struct WebDriverConfig { pub poller: Arc, /// The user agent to use when sending commands to the webdriver server. pub user_agent: HeaderValue, + /// The timeout duration for reqwest client requests. + pub reqwest_timeout: Duration, } impl Default for WebDriverConfig { @@ -68,6 +71,7 @@ pub struct WebDriverConfigBuilder { keep_alive: bool, poller: Option>, user_agent: Option>, + reqwest_timeout: Duration } impl Default for WebDriverConfigBuilder { @@ -83,6 +87,7 @@ impl WebDriverConfigBuilder { keep_alive: true, poller: None, user_agent: None, + reqwest_timeout: Duration::from_secs(120), } } @@ -108,12 +113,20 @@ impl WebDriverConfigBuilder { self } + /// Set the reqwest timeout. + pub fn reqwest_timeout(mut self, timeout: Duration) -> Self { + self.reqwest_timeout = timeout; + self + } + + /// Build `WebDriverConfig` using builder options. pub fn build(self) -> WebDriverResult { Ok(WebDriverConfig { keep_alive: self.keep_alive, poller: self.poller.unwrap_or_else(|| Arc::new(ElementPollerWithTimeout::default())), user_agent: self.user_agent.transpose()?.unwrap_or(WebDriverConfig::DEFAULT_USER_AGENT), + reqwest_timeout: self.reqwest_timeout }) } } diff --git a/thirtyfour/src/web_driver.rs b/thirtyfour/src/web_driver.rs index 51fb80a..077b408 100644 --- a/thirtyfour/src/web_driver.rs +++ b/thirtyfour/src/web_driver.rs @@ -95,9 +95,9 @@ impl WebDriver { S: Into, C: Into, { - // TODO: create builder and make timeout configurable. + #[cfg(feature = "reqwest")] - let client = create_reqwest_client(std::time::Duration::from_secs(120)); + let client = create_reqwest_client(config.reqwest_timeout); #[cfg(not(feature = "reqwest"))] let client = crate::session::http::null_client::create_null_client(); Self::new_with_config_and_client(server_url, capabilities, config, client).await From 45f4a576b9ed07b783d2be398960d809fe9e5a5c Mon Sep 17 00:00:00 2001 From: bylerbk Date: Tue, 1 Oct 2024 23:02:56 -0400 Subject: [PATCH 2/3] Adding back in comment --- thirtyfour/src/web_driver.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/thirtyfour/src/web_driver.rs b/thirtyfour/src/web_driver.rs index 077b408..0fd1227 100644 --- a/thirtyfour/src/web_driver.rs +++ b/thirtyfour/src/web_driver.rs @@ -96,6 +96,7 @@ impl WebDriver { C: Into, { + // TODO: create builder #[cfg(feature = "reqwest")] let client = create_reqwest_client(config.reqwest_timeout); #[cfg(not(feature = "reqwest"))] From 4ca5507905b6b4eeda17a5d4948d7d407912b77c Mon Sep 17 00:00:00 2001 From: bylerbk Date: Sun, 13 Oct 2024 16:18:58 -0400 Subject: [PATCH 3/3] Run fmt --- .DS_Store | Bin 0 -> 6148 bytes thirtyfour/.DS_Store | Bin 0 -> 6148 bytes thirtyfour/src/common/config.rs | 5 ++--- thirtyfour/src/web_driver.rs | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) create mode 100644 .DS_Store create mode 100644 thirtyfour/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..972cd4edaa880c4920326e614ca3f7e9a08797bb GIT binary patch literal 6148 zcmeHKJxe1&7=A_<4H5k4QV6cro`Ca<{n(%mOHI3PwdPIYaz1hsKz- z%oCODaeTO1ZKUm!p~zqe3Iqkdq5|^Ujj)149O2CS{g$@&Twgn_RO-iRowmZxdim~r z`*FkfH~;BBX*th^`6s4gvR4-^bW!)JqqII8;c}?{S@`|6};VlgwQA01ruD*!Q~Sr1<8UPFw< zKuj!V25I3?CY5MXm3_rfCY|=!#w8XrgC-qHSLQypva)X|rqj_L>u{*VU|53!K>=TZ zar1Fj`v2zW_kTYrdMNj{Wx2k%obC{f;{mdbHOXjAx#&;0-`t-!R7j@Xdk&`|zz*+HD zc`t7wZ!MzaZjY$(y8;AerhqA63hYe*oY`!HBSEW80aL&fhzjuc!J{yyiiKeKbf5}X z0ALT@!O-R(G|usgsbV1r56np_P*R;%Pz*MmiL=Vh<1cD4!nF4!N;2Y03Xu$vg literal 0 HcmV?d00001 diff --git a/thirtyfour/src/common/config.rs b/thirtyfour/src/common/config.rs index c50d4d9..e4e04cc 100644 --- a/thirtyfour/src/common/config.rs +++ b/thirtyfour/src/common/config.rs @@ -71,7 +71,7 @@ pub struct WebDriverConfigBuilder { keep_alive: bool, poller: Option>, user_agent: Option>, - reqwest_timeout: Duration + reqwest_timeout: Duration, } impl Default for WebDriverConfigBuilder { @@ -119,14 +119,13 @@ impl WebDriverConfigBuilder { self } - /// Build `WebDriverConfig` using builder options. pub fn build(self) -> WebDriverResult { Ok(WebDriverConfig { keep_alive: self.keep_alive, poller: self.poller.unwrap_or_else(|| Arc::new(ElementPollerWithTimeout::default())), user_agent: self.user_agent.transpose()?.unwrap_or(WebDriverConfig::DEFAULT_USER_AGENT), - reqwest_timeout: self.reqwest_timeout + reqwest_timeout: self.reqwest_timeout, }) } } diff --git a/thirtyfour/src/web_driver.rs b/thirtyfour/src/web_driver.rs index 0fd1227..a975de5 100644 --- a/thirtyfour/src/web_driver.rs +++ b/thirtyfour/src/web_driver.rs @@ -95,7 +95,6 @@ impl WebDriver { S: Into, C: Into, { - // TODO: create builder #[cfg(feature = "reqwest")] let client = create_reqwest_client(config.reqwest_timeout);