proxyparser 0.2.0

A cross-platform system proxy detector with strong support for complex enterprise PAC scripts
Documentation
# proxyparser

[![Crates.io](https://img.shields.io/crates/v/proxyparser.svg)](https://crates.io/crates/proxyparser)
[![Downloads](https://img.shields.io/crates/d/proxyparser.svg)](https://crates.io/crates/proxyparser)
[![CI](https://github.com/zongyangbigpolo/rustproxyparser/actions/workflows/ci.yml/badge.svg)](https://github.com/zongyangbigpolo/rustproxyparser/actions)

A cross-platform Rust library and CLI for resolving the proxy that should be
used for a URL. It supports environment variables, operating system proxy
settings, PAC files, and normalized proxy result parsing.

## Features

- Cross-platform system proxy detection
  - macOS: SystemConfiguration/CoreFoundation manual proxy and PAC settings
  - Windows: WinHTTP/IE proxy config, manual proxy lists, bypass rules, WPAD
  - Linux: GNOME `gsettings` and KDE `kreadconfig5`/`kreadconfig6`
- PAC support
  - Downloads `http://` and `https://` PAC files
  - Loads `file://` and local PAC files
  - Executes `FindProxyForURL` with `boa_engine`
  - Implements common PAC helpers such as `dnsResolve`, `myIpAddress`,
    `isInNet`, `shExpMatch`, `dnsDomainIs`, `localHostOrDomainIs`,
    `dnsDomainLevels`, and `weekdayRange`
- Proxy parsing and post-processing
  - Normalizes manual and PAC proxy results to full URLs
  - Deduplicates proxy entries
  - Supports protocol filtering and maximum result limits
  - Converts `SOCKS`/`SOCKS5` PAC directives to `socks5://`
  - Preserves `DIRECT` fallback semantics
- Priority order: environment variables -> system proxy/PAC -> `DIRECT`

## Validation report

![Validation report](assets/validation-report.svg)

Latest local validation:

| Check | Result | Notes |
| --- | --- | --- |
| `cargo fmt --check` | PASS | Rust formatting is clean |
| `cargo test` | PASS | 9 unit tests + 1 doctest passed |
| `cargo package --allow-dirty` | PASS | Crate packages and verifies successfully |
| Open-marker scan | PASS | No open implementation markers remain in source/config files |

The repository CI runs the same Rust checks natively on Ubuntu, macOS, and
Windows through GitHub Actions, so platform-specific system proxy modules are
validated on their own operating systems instead of relying on fragile local
cross-compilation.

## Installation

```bash
cargo install proxyparser
```

Or build from source:

```bash
git clone https://github.com/zongyangbigpolo/rustproxyparser.git
cd rustproxyparser
cargo build --release
```

## CLI usage

```bash
# Query the proxy for a specific URL
proxyparser https://httpbin.org/ip

# Use the default target (https://www.google.com)
proxyparser
```

Output is either `DIRECT` or a normalized proxy list, for example:

```text
Proxy for https://example.com -> http://proxy.local:8080; socks5://backup.local:1080; DIRECT
```

## Library usage

```rust
use proxyparser::find_proxy_for_url;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let proxy = find_proxy_for_url("https://example.com")?;
    println!("{proxy}");
    Ok(())
}
```

Proxy parser APIs are also public:

```rust
use proxyparser::proxy::{parse_proxy_result, ProxyParseOptions, ProxyScheme};

let options = ProxyParseOptions {
    allowed_schemes: Some(vec![ProxyScheme::Http, ProxyScheme::Socks5]),
    include_direct: true,
    max_proxies: 4,
};
let parsed = parse_proxy_result(
    "PROXY proxy.local:8080; SOCKS socks.local:1080; DIRECT",
    &options,
);

assert_eq!(
    parsed.to_proxy_string(),
    "http://proxy.local:8080; socks5://socks.local:1080; DIRECT"
);
```

## License

This project is licensed under the MIT License.