From 3ad6e02cdb4ba840f1663273ec77c9bb9cc83569 Mon Sep 17 00:00:00 2001 From: kurisu_u <73207840+lanyeeee@users.noreply.github.com> Date: Tue, 8 Oct 2024 20:49:31 +0800 Subject: [PATCH] refactor: remove internal proxy sys cache (#2442) 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 --- .github/workflows/ci.yml | 6 +----- src/proxy.rs | 14 +++----------- tests/proxy.rs | 4 ---- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5dfd0dbf7..571ad2df6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/src/proxy.rs b/src/proxy.rs index 880e2452e..61d1202bd 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -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; @@ -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 } @@ -876,9 +871,6 @@ impl Dst for Uri { } } -static SYS_PROXIES: Lazy> = - Lazy::new(|| Arc::new(get_sys_proxies(get_from_platform()))); - /// Get system proxies information. /// /// All platforms will check for proxy settings via environment variables. diff --git a/tests/proxy.rs b/tests/proxy.rs index 9231a3267..25d0f615c 100644 --- a/tests/proxy.rs +++ b/tests/proxy.rs @@ -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"; @@ -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.