diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-24 00:47:20 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-24 00:47:53 +0900 |
| commit | 340164c64e90d44b1bdf620b514166db1f76cc98 (patch) | |
| tree | 86195fe5ff8582b64e0324e9f40619e36c04948f /crates/shirabe/src/util/http/proxy_manager.rs | |
| parent | 8fe3390d064303b86133a1d2983144a4818a7121 (diff) | |
| download | php-shirabe-340164c64e90d44b1bdf620b514166db1f76cc98.tar.gz php-shirabe-340164c64e90d44b1bdf620b514166db1f76cc98.tar.zst php-shirabe-340164c64e90d44b1bdf620b514166db1f76cc98.zip | |
test: port more unimplemented tests
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/http/proxy_manager.rs')
| -rw-r--r-- | crates/shirabe/src/util/http/proxy_manager.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/crates/shirabe/src/util/http/proxy_manager.rs b/crates/shirabe/src/util/http/proxy_manager.rs index 37d73c0..d0ff9d9 100644 --- a/crates/shirabe/src/util/http/proxy_manager.rs +++ b/crates/shirabe/src/util/http/proxy_manager.rs @@ -1,5 +1,6 @@ //! ref: composer/src/Composer/Util/Http/ProxyManager.php +use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::{Mutex, OnceLock}; use crate::downloader::TransportException; @@ -9,12 +10,17 @@ use crate::util::http::RequestProxy; static INSTANCE: OnceLock<Mutex<Option<ProxyManager>>> = OnceLock::new(); +// Distinguishes ProxyManager instances so tests can mirror PHP `===` identity of the singleton, +// which the Rust value-based singleton does not otherwise expose. +static NEXT_GENERATION: AtomicU64 = AtomicU64::new(0); + #[derive(Debug)] pub struct ProxyManager { error: Option<String>, http_proxy: Option<ProxyItem>, https_proxy: Option<ProxyItem>, no_proxy_handler: std::cell::RefCell<Option<NoProxyPattern>>, + generation: u64, } impl ProxyManager { @@ -24,6 +30,7 @@ impl ProxyManager { http_proxy: None, https_proxy: None, no_proxy_handler: std::cell::RefCell::new(None), + generation: NEXT_GENERATION.fetch_add(1, Ordering::Relaxed), }; if let Err(e) = instance.get_proxy_data() { instance.error = Some(e.to_string()); @@ -41,6 +48,12 @@ impl ProxyManager { } } + /// For testing only: a unique id per constructed instance, used to mirror PHP `===` identity + /// comparison of the ProxyManager singleton across `get_instance`/`reset`. + pub fn __generation(&self) -> u64 { + self.generation + } + pub fn has_proxy(&self) -> bool { self.http_proxy.is_some() || self.https_proxy.is_some() } |
