Skip to content

Commit

Permalink
Requests using proxy settings from ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Oct 11, 2024
1 parent 62ab39c commit eaf32bb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ siphasher = "0.3.10"
strsim = "0.10.0"
clap = { version = "4.2.5", features = ["derive"] }
toml = "0.7.3"
ureq = { version = "2.6.2", features = ["json"] }
ureq = { version = "2.6.2", features = ["json", "socks-proxy"] }
walkdir = "2.3.2"
which = "4.4.0"
path-clean = "1.0.1"
Expand Down
5 changes: 4 additions & 1 deletion src/install/krate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ pub struct KrateResponse {
impl Krate {
pub fn new(name: &Tool) -> Result<Krate> {
let krate_address = format!("https://crates.io/api/v1/crates/{}", name);
let res = ureq::get(&krate_address)
let res = ureq::builder()
.try_proxy_from_env(true)
.build()
.get(&krate_address)
.set(
"user-agent",
&format!("wasm-pack/{}", VERSION.unwrap_or("unknown")),
Expand Down
1 change: 1 addition & 0 deletions src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ impl Crate {
fn check_wasm_pack_latest_version() -> Result<Crate> {
let url = "https://crates.io/api/v1/crates/wasm-pack";
let agent = ureq::builder()
.try_proxy_from_env(true)
.user_agent(&format!(
"wasm-pack/{} ({})",
WASM_PACK_VERSION.unwrap_or_else(|| "unknown"),
Expand Down
15 changes: 8 additions & 7 deletions src/test/webdriver/chromedriver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ struct GoodLatestVersions {
/// Retrieve the latest version of chromedriver from the json endpoints.
/// See: <https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints>
fn fetch_chromedriver_version() -> Result<String> {
let info: GoodLatestVersions = ureq::get(
"https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json",
)
.call()
.context("fetching of chromedriver's LATEST_RELEASE failed")?
.into_json()
.context("converting chromedriver version response to GoodLatestVersions failed")?;
let info: GoodLatestVersions = ureq::builder()
.try_proxy_from_env(true)
.build()
.get("https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json")
.call()
.context("fetching of chromedriver's LATEST_RELEASE failed")?
.into_json()
.context("converting chromedriver version response to GoodLatestVersions failed")?;

let version = info
.channels
Expand Down
14 changes: 8 additions & 6 deletions src/test/webdriver/geckodriver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ fn should_load_geckodriver_version_from_stamp(json: &serde_json::Value) -> bool
}

fn fetch_latest_geckodriver_tag_json() -> Result<String> {
let content: serde_json::Value =
ureq::get("https://github.com/mozilla/geckodriver/releases/latest")
.set("Accept", "application/json")
.call()
.context("fetching of geckodriver's latest release data failed")?
.into_json()?;
let content: serde_json::Value = ureq::builder()
.try_proxy_from_env(true)
.build()
.get("https://github.com/mozilla/geckodriver/releases/latest")
.set("Accept", "application/json")
.call()
.context("fetching of geckodriver's latest release data failed")?
.into_json()?;

get_version_from_json(content)
}
Expand Down

0 comments on commit eaf32bb

Please sign in to comment.