Skip to content

Commit

Permalink
refactor: remove internal proxy sys cache (#2442)
Browse files Browse the repository at this point in the history
This removes some cache code that would only check for system proxies one time. Now it will check every time a `Client` is built.

Technically, removes the crate feature `__internal_proxy_sys_no_cache`, but that was unstable and you weren't using it, right?

Closes #2441
  • Loading branch information
lanyeeee authored Oct 8, 2024
1 parent 95fec09 commit 3ad6e02
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,12 @@ jobs:

include:
- name: linux / stable
test-features: "--features __internal_proxy_sys_no_cache"
- name: linux / beta
rust: beta
test-features: "--features __internal_proxy_sys_no_cache"
# - name: linux / nightly
# rust: nightly
# test-features: "--features __internal_proxy_sys_no_cache"
- name: macOS / stable
os: macOS-latest
test-features: "--features __internal_proxy_sys_no_cache"

- name: windows / stable-x86_64-msvc
os: windows-latest
Expand Down Expand Up @@ -272,7 +268,7 @@ jobs:
run: |
cargo clean
cargo update -Z minimal-versions
cargo update -p proc-macro2 --precise 1.0.62
cargo update -p proc-macro2 --precise 1.0.87
cargo check
cargo check --all-features
Expand Down
14 changes: 3 additions & 11 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::into_url::{IntoUrl, IntoUrlSealed};
use crate::Url;
use http::{header::HeaderValue, Uri};
use ipnet::IpNet;
use once_cell::sync::Lazy;
use percent_encoding::percent_decode;
use std::collections::HashMap;
use std::env;
Expand Down Expand Up @@ -280,13 +279,9 @@ impl Proxy {
}

pub(crate) fn system() -> Proxy {
let mut proxy = if cfg!(feature = "__internal_proxy_sys_no_cache") {
Proxy::new(Intercept::System(Arc::new(get_sys_proxies(
get_from_platform(),
))))
} else {
Proxy::new(Intercept::System(SYS_PROXIES.clone()))
};
let mut proxy = Proxy::new(Intercept::System(Arc::new(get_sys_proxies(
get_from_platform(),
))));
proxy.no_proxy = NoProxy::from_env();
proxy
}
Expand Down Expand Up @@ -876,9 +871,6 @@ impl Dst for Uri {
}
}

static SYS_PROXIES: Lazy<Arc<SystemProxyMap>> =
Lazy::new(|| Arc::new(get_sys_proxies(get_from_platform())));

/// Get system proxies information.
///
/// All platforms will check for proxy settings via environment variables.
Expand Down
4 changes: 0 additions & 4 deletions tests/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ async fn test_no_proxy() {
assert_eq!(res.status(), reqwest::StatusCode::OK);
}

#[cfg_attr(not(feature = "__internal_proxy_sys_no_cache"), ignore)]
#[tokio::test]
async fn test_using_system_proxy() {
let url = "http://not.a.real.sub.hyper.rs/prox";
Expand All @@ -175,9 +174,6 @@ async fn test_using_system_proxy() {
async { http::Response::default() }
});

// Note: we're relying on the `__internal_proxy_sys_no_cache` feature to
// check the environment every time.

// save system setting first.
let system_proxy = env::var("http_proxy");
// set-up http proxy.
Expand Down

0 comments on commit 3ad6e02

Please sign in to comment.