Expand description
Detect — and on Windows, macOS and Linux watch — the operating system’s proxy settings.
read answers once, starting no watcher and arming no notification route:
use proxy_watch::{Scheme, read};
let config = read()?;
match config.effective.endpoint_for(Scheme::Https) {
Some(endpoint) => println!("https goes through {endpoint}"),
None => println!("https is direct"),
}ProxyWatcher follows the settings instead — a Stream of WatchEvent that
opens with a snapshot, then publishes changes coalesced over
WatchOptions::debounce (200 ms). It runs its own OS threads, so it needs no async
runtime. Where there is no store to read — any other platform, or a Linux host with no
desktop — the answer is Error::Unsupported, which means “read ProxyEnv::from_env()
instead”, not “give up”.
resolve() (behind the resolve feature, so unlinked here) turns a snapshot and a URL
into the ordered endpoints to try, bypass rules applied; a host on PAC or WPAD stops it
with Error::PacNotSupported until pac and an engine — pac-boa, or
pac-windows-native on Windows — are on. The remaining flags are linux-gnome and
linux-kde (the Linux stores, on by default), tokio for a
tokio::sync::watch::Receiver, and tracing for lifecycle logs.
The README carries the feature table, the per-OS map of where these settings live, and a runnable example for each of the above.
§Platform coverage
Windows, GNOME and KDE are exercised on real machines. Under Flatpak or snap without
dconf the Linux backend falls back to the desktop portal, which has no change
notification of its own — set WatchOptions::poll_interval to poll — or reports
Error::Sandboxed.
Unverified: the macOS backend and that sandbox path have only ever run in CI — no
Mac, no Flatpak, no Snap.
Risk: macOS reads a missing or unexpected answer as “nothing is configured” rather
than as an error, so a host that does have a proxy is reported as having none. The
sandbox path fails loudly instead, so what is open there is whether the detection fires
at all, not what it does once it has.
Symptom: on a machine whose settings plainly show a proxy, the stream yields
ProxyMode::Direct and never publishes an error. src/sys/mac/mod.rs,
src/sys/linux/sandbox.rs and src/sys/linux/portal.rs carry the per-backend form.
Modules§
- pac
pac - PAC evaluation (
pacfeature, off by default): script →Vec<ProxyStep>likeresolve. - parse
- Pure parsers for OS proxy string formats.
Structs§
- Bypass
Rules - Destinations that must not go through a proxy
(
parse::no_proxy/parse::proxy_override). - Proxy
Auth - Credentials for a proxy endpoint (HTTP Basic only).
- Proxy
Config - Point-in-time system proxy snapshot.
- Proxy
Endpoint - Concrete proxy address. IPv6 brackets resolved at parse; use
authority.#[non_exhaustive]— construct vianew/parse. - Proxy
Env - Env snapshot of
*_proxy/no_proxy(not aStream;ProxyWatcherdoes not merge these in — except where an OS setting names them, which KDE’sProxyType=4does). - Proxy
Watcher - OS proxy watcher: initial snapshot, then debounced changes (equality ignores
captured_at). Own OS threads — one, and on Linux one more per live source, plus one forWatchOptions::poll_interval(elsewhere that interval shortens the single thread’s own wait instead of adding one). Drop joins them.ProxyWatcher::healthfor route liveness. Win/macOS/Linux; elseError::Unsupported. Applies no*_proxyconvention of its own — only KDE’sProxyType = 4builds aProxyEnv, from the variableskioslavercnames. - Rejected
Value - One fail-soft drop with a typed reason and origin.
- Url
- Re-export of
url::UrlforProxyMode::Pac. A parsed URL record. - Watch
Health - Liveness of change-notification routes (
ProxyWatcher::health). - Watch
Options - Tuning knobs for
ProxyWatcher::with_options(#[non_exhaustive]— useWatchOptions::new/with_*). - Watch
State - One internally consistent observation of a watcher.
Enums§
- EnvPrecedence
- Where the process environment ranks against the OS settings in
ProxyConfig::with_env. - Error
- Errors from reading OS proxy configuration, and from routing a URL through what was read.
- Host
- Re-export of
url::Host(IPv6 brackets already resolved). The host name of an URL. - Host
Pattern - A single entry of a bypass list.
- IpNet
- Re-export of
ipnet::IpNetforHostPattern::Cidr. An IP network address, either IPv4 or IPv6. - Proxy
Config Source - Where a
ProxyModecame from.ProxyConfigkeeps all of them for explanation. - Proxy
Entry - Whether a given
Schemeuses a proxy at all. - Proxy
Mode - What a single configuration source says about proxying.
- Proxy
Scheme - The wire protocol used to reach the proxy itself.
- Proxy
Step resolve - Routing decisions, behind the
resolvefeature (on by default). One way to reach a destination (resolve). - Rejection
Kind - Why one configuration value was ignored.
- Rejection
Source - Where a rejected value was read from.
- Scheme
- Request scheme a proxy setting applies to (
ProxyMode::Manualper_schemekey). NotProxyScheme(how to talk to the proxy). - Watch
Event - Stream item of
ProxyWatcher: a state snapshot or a failed re-read, each stamped with the watcher’sWatchStateas it stood at delivery.
Constants§
- CGI_
MARKER_ VAR - The variable whose presence with a method in it marks a CGI environment (see
Error::CgiHttpProxy). - DEFAULT_
DEBOUNCE - The default debounce window (200 ms).
- LOCAL_
TOKEN - The Windows
ProxyOverridetoken that bypasses dot-less (intranet) host names. - NO_
LOOPBACK_ TOKEN - Windows
<-loopback>: subtracts the whole implicit bypass set — loopback and link-local — from the entries written before it. Parsed toHostPattern::SubtractImplicit; seeBypassRules::bypass_loopback.
Traits§
- Stream
- Re-export of
futures_core::Stream. A stream of values produced asynchronously.
Functions§
- read
- Read the OS proxy configuration once, without starting a watcher.
- read_
with_ options read, with the one option a read can honour:WatchOptions::watch_group_policy. The debounce and poll-interval fields describe a watcher this call never starts, so they are ignored.- resolve
resolve - Routing decisions, behind the
resolvefeature (on by default). Decide how to reachurlunderconfig. - resolve_
with_ pac pacandresolve - Routing decisions that may need a PAC script, behind the
pacfeature (off by default). Likeresolve, but evaluates PAC when the mode requires it. - watch_
channel tokio - The tokio bridge, behind the
tokiofeature (off by default). Drivewatcherinto atokio::sync::watchchannel (clonewatch::Receiverfor fan-out).