Skip to content

Commit

Permalink
[rust] Reuse driver mirror URL (when available) to discover Firefox v…
Browse files Browse the repository at this point in the history
…ersions (#13941) (#14493)

Co-authored-by: Diego Molina <[email protected]>
  • Loading branch information
bonigarcia and diemol authored Sep 17, 2024
1 parent 2970ad3 commit 6459008
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rust/src/firefox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ impl SeleniumManager for FirefoxManager {
_ => {
self.assert_online_or_err(OFFLINE_REQUEST_ERR_MSG)?;

let driver_version_url =
self.get_driver_mirror_versions_url_or_default(DRIVER_VERSIONS_URL);
let driver_version = match parse_json_from_url::<GeckodriverReleases>(
self.get_http_client(),
DRIVER_VERSIONS_URL,
&driver_version_url,
) {
Ok(driver_releases) => {
let major_browser_version_int =
Expand Down
20 changes: 20 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,26 @@ pub trait SeleniumManager {
}
}

fn get_driver_mirror_versions_url_or_default<'a>(&'a self, default_url: &'a str) -> String {
let driver_mirror_url = self.get_driver_mirror_url();
if !driver_mirror_url.is_empty() {
let driver_versions_path = default_url.rfind('/').map(|i| &default_url[i + 1..]);
if let Some(path) = driver_versions_path {
let driver_mirror_versions_url = if driver_mirror_url.ends_with('/') {
format!("{}{}", driver_mirror_url, path)
} else {
format!("{}/{}", driver_mirror_url, path)
};
self.get_logger().debug(format!(
"Using mirror URL to discover driver versions: {}",
driver_mirror_versions_url
));
return driver_mirror_versions_url;
}
}
default_url.to_string()
}

fn get_driver_mirror_url_or_default<'a>(&'a self, default_url: &'a str) -> String {
self.get_url_or_default(self.get_driver_mirror_url(), default_url)
}
Expand Down

0 comments on commit 6459008

Please sign in to comment.