Skip to main content

parse_find_proxy_result

Function parse_find_proxy_result 

Source
pub fn parse_find_proxy_result(result: &str) -> Result<Vec<ProxyStep>, Error>
Available on crate feature pac only.
Expand description

Parse a FindProxyForURL return string into an ordered fallback chain.

Tokens are separated by ; or newlines; newline separation is specific to this crate and differs from Chromium. Keywords are case-insensitive: DIRECT; PROXY/HTTP→ProxyStep::Http; HTTPS→HTTPS; SOCKS/SOCKS4→SOCKS4; SOCKS5→ProxyScheme::Socks5h (remote DNS). An address without a port uses ProxyScheme::default_port for the keyword’s scheme. Addresses must be bare authorities: /, ? or #, including in scheme://, invalidates the whole candidate. Bad tokens are skipped, repeats collapse, and embedded credentials are dropped. An empty usable chain returns Error::PacInvalidResult.

let steps = parse_find_proxy_result("PROXY a:1; SOCKS5 b:2; DIRECT")?;
assert_eq!(steps.len(), 3);
assert_eq!(steps[0].endpoint().unwrap().authority(), "a:1");
assert_eq!(steps[1].scheme(), Some("socks5"));
assert_eq!(steps[1].to_url().unwrap().as_str(), "socks5h://b:2");
assert!(steps[2].is_direct());

§Errors

Error::PacInvalidResult when no candidate in the string could be understood, including the empty string.