proxyparser 0.2.0

A cross-platform system proxy detector with strong support for complex enterprise PAC scripts
Documentation
// src/system_proxy/mod.rs

#[cfg(target_os = "macos")]
pub mod macos;

#[cfg(target_os = "linux")]
pub mod linux;

#[cfg(target_os = "windows")]
pub mod windows;

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum SystemProxyConfig {
    PacUrl(String),
    Manual(String),
}

impl SystemProxyConfig {
    pub fn as_string(&self) -> &str {
        match self {
            SystemProxyConfig::PacUrl(value) | SystemProxyConfig::Manual(value) => value,
        }
    }
}

/// 统一获取当前平台的系统代理
/// 返回值:
/// - Some(String):手动代理(如 "http://127.0.0.1:8080")或 PAC URL(如 "http://.../proxy.pac")
/// - None:无代理配置或不支持
pub fn get_system_proxy(url: &str) -> Option<String> {
    get_system_proxy_config(url).map(|config| config.as_string().to_string())
}

pub fn get_system_proxy_config(url: &str) -> Option<SystemProxyConfig> {
    #[cfg(target_os = "macos")]
    {
        macos::get_macos_proxy_config(url)
    }
    #[cfg(target_os = "linux")]
    {
        linux::get_linux_proxy_config(url)
    }
    #[cfg(target_os = "windows")]
    {
        windows::get_windows_proxy_config(url)
    }
    #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
    {
        let _ = url; // 未使用参数警告消除
        None
    }
}