From 7992c9321979d2f61bc96bbb54a84248a1bb566b Mon Sep 17 00:00:00 2001 From: 0x676e67 Date: Sat, 11 Jan 2025 17:58:05 +0800 Subject: [PATCH] feat(proxy): remove system proxy cache (#309) * Remove system proxy cache * fmt --- Cargo.toml | 3 --- src/client/http.rs | 26 ++++++++++++-------------- src/proxy.rs | 15 ++++----------- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 48953e9a..f044e2ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,9 +62,6 @@ socks = ["dep:tokio-socks"] native-roots = ["dep:rustls-native-certs"] webpki-roots = ["dep:webpki-root-certs"] -# Optional disable internal proxy cache -internal_proxy_sys_no_cache = [] - # Optional enable impersonate from str impersonate_str = [] diff --git a/src/client/http.rs b/src/client/http.rs index 63a8c89c..a84d215d 100644 --- a/src/client/http.rs +++ b/src/client/http.rs @@ -1398,7 +1398,9 @@ impl Client { }), } } +} +impl Client { /// Get the client user agent #[inline] pub fn user_agent(&self) -> Option<&HeaderValue> { @@ -1633,7 +1635,7 @@ impl Client { Ok(self) } - /// private mut ref to inner + /// Private mut ref to inner #[inline(always)] fn inner_mut(&mut self) -> &mut ClientRef { Arc::make_mut(&mut self.inner) @@ -1796,22 +1798,14 @@ pin_project! { url: Url, headers: HeaderMap, body: Option>, - version: Option, - urls: Vec, - retry_count: usize, max_retry_count: usize, - redirect: Option, - cookie_store: CookieStoreOption, - network_scheme: NetworkScheme, - client: Arc, - #[pin] in_flight: ResponseFuture, #[pin] @@ -1900,8 +1894,6 @@ impl PendingRequest { } fn is_retryable_error(err: &(dyn std::error::Error + 'static)) -> bool { - use hyper2::h2; - // pop the legacy::Error let err = if let Some(err) = err.source() { err @@ -1910,15 +1902,20 @@ fn is_retryable_error(err: &(dyn std::error::Error + 'static)) -> bool { }; if let Some(cause) = err.source() { - if let Some(err) = cause.downcast_ref::() { + if let Some(err) = cause.downcast_ref::() { // They sent us a graceful shutdown, try with a new connection! - if err.is_go_away() && err.is_remote() && err.reason() == Some(h2::Reason::NO_ERROR) { + if err.is_go_away() + && err.is_remote() + && err.reason() == Some(hyper2::h2::Reason::NO_ERROR) + { return true; } // REFUSED_STREAM was sent from the server, which is safe to retry. // https://www.rfc-editor.org/rfc/rfc9113.html#section-8.7-3.2 - if err.is_reset() && err.is_remote() && err.reason() == Some(h2::Reason::REFUSED_STREAM) + if err.is_reset() + && err.is_remote() + && err.reason() == Some(hyper2::h2::Reason::REFUSED_STREAM) { return true; } @@ -2111,6 +2108,7 @@ impl Future for PendingRequest { return Poll::Ready(Err(error::url_bad_uri(self.url.clone()))); } }; + let body = match self.body { Some(Some(ref body)) => Body::reusable(body.clone()), _ => Body::empty(), diff --git a/src/proxy.rs b/src/proxy.rs index 53fc517b..5e8d63a8 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -1,7 +1,7 @@ use std::fmt; #[cfg(feature = "socks")] use std::net::SocketAddr; -use std::sync::{Arc, LazyLock}; +use std::sync::Arc; use crate::into_url::{IntoUrl, IntoUrlSealed}; use crate::Url; @@ -277,16 +277,9 @@ impl Proxy { } pub(crate) fn system() -> Proxy { - static SYS_PROXIES: LazyLock> = - LazyLock::new(|| Arc::new(get_sys_proxies(get_from_platform()))); - - 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 }