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 uses the same separator, but this crate’s matching follows
Chromium’s ProxyHostMatchingRules where the two readers differ.
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 follow from reading * as Chromium’s glob rather than
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). An entry whose body ends in a label that
reads as a number (.example.123) goes to BypassRules::rejected. This is
unreachable for the special schemes these lists are written about, but a
custom://a.example.123/ it would have matched is proxied instead. That URL matters
because resolve sends an unknown scheme to the catch-all entry rather than declining
it.
An IPv4 address written other than as four decimal octets is read the URL way, as
Chromium’s IPAddress::AssignFromIPLiteral reads it, in an address entry and in a CIDR
block whose address has four parts: 012.1.2.3 is 10.1.2.3 and 012.1.2.0/24 is
10.1.2.0/24. A block with a short-form address (192.168.1/24) is an error. Limitation: curl and Go read neither
as an address, so under them the entry matches nothing, and this answers Direct for a
destination those two proxy.
let rules = parse::no_proxy("<local>,<-loopback>");
assert!(rules.excludes_simple_hostnames());
assert!(!rules.bypass_loopback());