pub struct PacResolver { /* private fields */ }pac only.Expand description
Routes a whole ProxyConfig to whichever PAC engine answers its mode.
The order, first match wins:
Direct/Manual:resolve, bypass list included. Ascriptis ignored.- A URL with no host (
mailto:,data:): Direct, and no engine runs. - A
scriptthe caller passed: the JS engine, whichever PAC mode is effective. A caller who fetched the body has already answered the question the mode asks. PacInline: the JS engine, with the body the mode carries.
“The JS engine” is the evaluator attached with with_evaluator
when there is one, else evaluate under this resolver’s PacPolicy.
5. Pac / WpadAutoDetect
with a native resolver attached (with_native): WinHttpPacResolver::resolve_config
(Windows + pac-windows-native) or CfNetworkPacResolver::resolve_config (macOS +
pac-macos-native, iOS + pac-ios-native), which downloads, and discovers once the resolver was built
with_wpad(true); AndroidPacResolver::resolve_config (Android +
pac-android-native), which asks the system PAC service through ProxySelector.
6. Otherwise what resolve_with_pac says: Pac →
Error::PacFetchRequired, WpadAutoDetect → Error::PacNotSupported.
A failure is reported, never retried on the other engine: a native error does not fall
back to JS, and a JS error does not fall back to the native one. The two engines
disagree about what a script is allowed to see: PacPolicy governs the JS engine
only, and the native one uses real DNS and the real local address, so a silent retry
would change which policy produced the answer.
The two budgets are independent: PacPolicy::timeout bounds a JS evaluation, and the
WinHTTP and CFNetwork resolvers’ timeout bounds a native resolution, download and
discovery included. The Android resolver has no timeout of its own.
With no evaluator attached and no QuickJS engine compiled in (pac-quickjs off, or on
Android or iOS, where the feature builds without one), the JS arms are
Error::PacEngineUnavailable.
use proxy_watch::pac::{PacPolicy, PacResolver};
use proxy_watch::{ProxyConfig, ProxyConfigSource, ProxyMode, ProxyStep, Url};
let mode = ProxyMode::pac_inline(
"function FindProxyForURL(u, h) { return 'DIRECT'; }".to_owned(),
);
let config = ProxyConfig::from_source(ProxyConfigSource::Registry, mode);
let url = Url::parse("http://example.net/").unwrap();
let resolver = PacResolver::new(PacPolicy::new());
assert_eq!(resolver.resolve_config(&config, &url, None)?, vec![ProxyStep::Direct]);Implementations§
Source§impl PacResolver
impl PacResolver
Sourcepub fn new(policy: PacPolicy) -> Self
pub fn new(policy: PacPolicy) -> Self
A resolver that runs PAC scripts under policy and has no native engine attached.
Sourcepub fn with_native(self, native: Native) -> Self
Available on pac_native only.
pub fn with_native(self, native: Native) -> Self
pac_native only.Attach the native resolver (WinHttpPacResolver on Windows, CfNetworkPacResolver
on macOS and iOS, AndroidPacResolver on Android) for
Pac and
WpadAutoDetect with no caller-supplied script.
Takes a built resolver rather than building one, so that a failure to open a
session is the caller’s to see, not a silent fall back to “fetch it yourself”, and
so that its with_wpad choice is the caller’s.
Sourcepub fn with_system_native(self) -> Result<Self, Error>
pub fn with_system_native(self) -> Result<Self, Error>
Attach this target’s native resolver, built with its defaults (WPAD off), when a
pac-*-native feature enables one; otherwise return self unchanged. Available
without cfg guards in cross-platform applications.
§Errors
What building the native resolver returns: on Windows, a WinHTTP session that fails to open.
Sourcepub fn native(&self) -> Option<&Native>
Available on pac_native only.
pub fn native(&self) -> Option<&Native>
pac_native only.The attached native resolver, if any.
Sourcepub fn with_evaluator(
self,
evaluator: impl PacEvaluator + Send + Sync + 'static,
) -> Self
pub fn with_evaluator( self, evaluator: impl PacEvaluator + Send + Sync + 'static, ) -> Self
Run the JS arms on evaluator instead of evaluate, for example
a SubprocessEvaluator (feature pac-subprocess), so that a script from the
configuration runs in a worker process.
The evaluator runs under the policy it was built with; this resolver’s
policy then governs nothing. The native arm is unchanged: a native
resolver still answers URL and WPAD modes when no script is passed.
Sourcepub fn policy(&self) -> &PacPolicy
pub fn policy(&self) -> &PacPolicy
The policy evaluate runs under when no evaluator is attached.
Sourcepub fn resolve_config(
&self,
config: &ProxyConfig,
url: &Url,
script: Option<&PacScript>,
) -> Result<Vec<ProxyStep>, Error>
pub fn resolve_config( &self, config: &ProxyConfig, url: &Url, script: Option<&PacScript>, ) -> Result<Vec<ProxyStep>, Error>
Resolve url under config, routing as the type documentation lists.
§Errors
Whatever the engine the mode routed to returns: resolve_with_pac’s errors for the
JS arms and the fall-through (an attached evaluator’s own errors in place of
evaluate’s), and the native resolver’s resolve_config’s for the
native arm.