pub struct OriginProxy { /* private fields */ }proxy and system-proxy only.Expand description
A proxy policy resolved for exactly one HTTP(S) origin (system-proxy).
Resolution snapshots the process environment and supported native settings.
Uppercase variables, including empty values, precede lowercase variants.
Per-scheme environment proxies precede native settings, then ALL_PROXY.
Nonempty environment overrides with unusable URLs skip native discovery and
fall back to a usable ALL_PROXY, or direct access. Explicit options are
validated instead. Presence of REQUEST_METHOD disables automatic selection.
Native discovery reads global macOS HTTP/HTTPS/SOCKS settings, Windows static
Internet Settings (including protocol maps and per-machine policy), and
GNOME/KDE desktop settings. Native bypass grammars remain distinct from
NO_PROXY. Empty local bypass overrides suppress native exclusions too.
macOS/Linux native SOCKS5 settings use proxy-side DNS. PAC/WPAD, saved
passwords, and per-interface/VPN settings are not resolved; portal-only
sources are rejected.
Native bypass decisions are evaluated for this origin. Do not reuse the
resulting client for other origins or follow redirects automatically. Use
Self::check_origin before dispatch if URLs are supplied dynamically. For
another origin, resolve a separate policy and configure a separate client.
The reqwest feature adds configure_reqwest; it disables redirects but
cannot restrict arbitrary requests made through a raw reqwest client.
This type does not configure service credentials, TLS trust, timeouts, or request/response semantics. Debug output omits proxy URLs and credentials.
Implementations§
Source§impl OriginProxy
impl OriginProxy
Sourcepub fn resolve(url: &Url, options: &ProxyOptions) -> Result<Self, Error>
pub fn resolve(url: &Url, options: &ProxyOptions) -> Result<Self, Error>
Resolves proxy settings before constructing a client or accessing keys.
§Errors
Rejects non-HTTP(S) targets with Error::InvalidOrigin. Invalid
explicit proxy URLs fail even when bypassed. Native read/configuration
failures and unsupported resolver sources retain their proxy error.
Sourcepub fn origin(&self) -> &Origin
pub fn origin(&self) -> &Origin
The bound scheme, host, and effective port, without paths or credentials.
Sourcepub fn proxy_url(&self) -> Option<&Url>
pub fn proxy_url(&self) -> Option<&Url>
The selected endpoint before applying Self::no_proxy rules.
None selects direct access. Some is a candidate: adapters must still
apply the NO_PROXY list, including * for IP literals. Native exclusions
have already been evaluated for this origin. The URL may contain proxy
credentials; do not log it without redaction.
Sourcepub fn no_proxy(&self) -> &str
pub fn no_proxy(&self) -> &str
Environment-syntax bypass rules to apply to Self::proxy_url.
This is the effective inherited or explicitly replaced NO_PROXY list;
native exclusion syntax is never copied into it. The reqwest adapter
applies it automatically. Other adapters must preserve its semantics.
Sourcepub fn check_origin(&self, url: &Url) -> Result<(), Error>
pub fn check_origin(&self, url: &Url) -> Result<(), Error>
Checks a destination before dispatch through an origin-scoped client.
§Errors
Returns Error::InvalidOrigin if scheme, host, or effective port differs.
Source§impl OriginProxy
impl OriginProxy
Sourcepub fn proxy_for_hyper(&self) -> Result<Option<&Url>, Error>
Available on crate feature hyper only.
pub fn proxy_for_hyper(&self) -> Result<Option<&Url>, Error>
hyper only.Returns this origin’s effective endpoint for a Hyper connector (hyper).
Applies NO_PROXY using the same matcher as reqwest, including the shared
wildcard fix for IP literals. Native exclusions were resolved earlier.
This does not perform backend environment/system discovery. The returned
URL retains credentials; use it only for Self::origin. The caller
owns CONNECT/SOCKS support, TLS, timeouts, and connection pooling.
§Errors
Returns Error::InvalidOrigin if the origin cannot be represented as
an HTTP URI for matching.
Source§impl OriginProxy
impl OriginProxy
Sourcepub fn configure_reqwest(
&self,
builder: ClientBuilder,
) -> Result<ClientBuilder, Error>
Available on crate feature reqwest only.
pub fn configure_reqwest( &self, builder: ClientBuilder, ) -> Result<ClientBuilder, Error>
reqwest only.Installs this origin’s proxy policy on a reqwest builder (reqwest).
Replaces existing proxies, disables automatic proxy discovery and redirects, and prefers system-resolved IPv4 for SOCKS4. TLS, service credentials, and timeouts remain the caller’s settings. Apply this after any other proxy/redirect settings and then build the client.
The resulting raw reqwest client must only send requests to
Self::origin. Use Self::check_origin before dispatching dynamic
URLs. Requests to other origins and manual redirects need separately
resolved clients; this adapter does not enforce request URL restrictions.
use asimov_http::proxy::{OriginProxy, ProxyOptions};
let url = reqwest::Url::parse("https://example.com/resource")?;
let proxy = OriginProxy::resolve(&url, &ProxyOptions::default())?;
let client = proxy.configure_reqwest(reqwest::Client::builder())?.build()?;
proxy.check_origin(&url)?;
let response = client.get(url).send().await?;§Errors
Returns reqwest’s error if the selected endpoint cannot configure a proxy.