pub fn no_proxy(spec: &str) -> BypassRulesExpand description
Parse no_proxy into BypassRules: *, CIDR, domains, :port, and a localhost
bypass that stays on unless an entry clears it. Entries are separated by , alone — not
whitespace and not ;, which is what Go’s httpproxy does and what KDE’s readers do
with NoProxyFor. Malformed → BypassRules::rejected. An entry
that repeats one already in BypassRules::patterns is dropped, first spelling kept,
so the list can be shorter than the string had entries.
Go’s httpproxy is the nearest relative and the separator above is its rule, but this
does not implement it: what an entry matches follows Chromium’s
ProxyHostMatchingRules wherever the readers answer differently, and the rest of this
doc is where they do. None of it is a corner case.
The Windows tokens <local> and <-loopback> are read here too, which Go does not
do — Chromium feeds the no_proxy environment variable through the same
ProxyHostMatchingRules::ParseFromString as any other bypass list, and that is where the
tokens are recognised. See proxy_override, which differs in its separators and in
reading a bare name as the one host rather than as the domain under it.
Two further departures from Go, both downstream of reading * as Chromium’s glob
rather than as Go’s optional prefix. A star is matched against the destination’s text,
so *.*.*.1 bypasses 10.0.0.1, where Go answers no domain entry at all against an
address destination (httpproxy/proxy.go:367-369). And an entry whose body ends in a
label that reads as a number — .example.123 — goes to BypassRules::rejected
rather than being kept: unreachable for the special schemes these lists are written
about, but a custom://a.example.123/ it would have matched is proxied instead — and
that URL is one this crate answers about, since resolve (the resolve feature’s entry
point) sends an unknown scheme to the catch-all entry rather than declining it.
let rules = parse::no_proxy("<local>,<-loopback>");
assert!(rules.excludes_simple_hostnames());
assert!(!rules.bypass_loopback());