Skip to content

Commit

Permalink
Merge pull request #1592 from webern/issue-1332
Browse files Browse the repository at this point in the history
metricdog and updog: remove reqwest proxy workaround
  • Loading branch information
webern authored May 26, 2021
2 parents 0f9993e + 207347d commit f3ac7c8
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 47 deletions.
28 changes: 0 additions & 28 deletions sources/metricdog/src/metricdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ impl Metricdog {

fn send_get_request(url: Url, timeout_sec: Option<u64>) -> Result<()> {
debug!("sending: {}", url.as_str());
fix_https_proxy_env();
let client = Client::builder()
.timeout(Duration::from_secs(
timeout_sec.unwrap_or(DEFAULT_TIMEOUT_SECONDS),
Expand All @@ -157,30 +156,3 @@ impl Metricdog {
Ok(())
}
}

/// reqwest needs a URL protocol scheme to be present, but other implementations assume
/// `http://` as the scheme when none is present. We need to check the `HTTPS_PROXY` env and
/// reset it with `http://` when no scheme is present. This can be removed when we are using
/// reqwest >= 0.11.1
// TODO - remove this workaround, see /~https://github.com/bottlerocket-os/bottlerocket/issues/1332
fn fix_https_proxy_env() {
let proxy = match std::env::var("HTTPS_PROXY") {
Ok(s) if !s.is_empty() => s,
_ => return,
};

// try to parse it as a URL. if it works, a scheme is present
if Url::parse(&proxy).is_ok() {
return;
}

// since the URL could not be parsed, try parsing with http:// prepended
let proxy = format!("http://{}", proxy);

// use URL again to see if the proxy value is now valid
if Url::parse(&proxy).is_ok() {
debug!("Adding a scheme to HTTPS_PROXY: '{}'", proxy);
// success, so let's change the HTTPS_PROXY value for the sake of reqwest
std::env::set_var("HTTPS_PROXY", proxy);
}
}
19 changes: 0 additions & 19 deletions sources/updater/updog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,25 +471,6 @@ fn set_https_proxy_environment_variables(
_ => return Ok(()),
};

// TODO - remove this workaround, /~https://github.com/bottlerocket-os/bottlerocket/issues/1332
// reqwest needs a URL protocol scheme to be present, but other implementations assume
// `http://` as the scheme when none is present. We need to check the `HTTPS_PROXY` env and
// reset it with `http://` when no scheme is present. This workaround will no longer be needed
// when both bottlerocket and tough are using reqwest >= 0.11.1.
let proxy = if Url::parse(&proxy).is_ok() {
// the proxy value is OK, it has a scheme
debug!("setting HTTPS_PROXY={}", proxy);
proxy
} else {
// try prepending the default scheme
let prepended = format!("http://{}", proxy);
// now we expect a valid URL
let _ = Url::parse(&prepended).context(error::Proxy { proxy })?;
// now we know we have a string that will work with reqwest
debug!("prepended https:// and setting HTTPS_PROXY={}", prepended);
prepended
};

std::env::set_var("HTTPS_PROXY", &proxy);
if let Some(no_proxy) = no_proxy {
if !no_proxy.is_empty() {
Expand Down

0 comments on commit f3ac7c8

Please sign in to comment.