Skip to main content

OriginProxy

Struct OriginProxy 

Source
pub struct OriginProxy { /* private fields */ }
Available on crate features 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

Source

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.

Source

pub fn origin(&self) -> &Origin

The bound scheme, host, and effective port, without paths or credentials.

Source

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.

Source

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.

Source

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

Source

pub fn proxy_for_hyper(&self) -> Result<Option<&Url>, Error>

Available on crate feature 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

Source

pub fn configure_reqwest( &self, builder: ClientBuilder, ) -> Result<ClientBuilder, Error>

Available on crate feature 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.

Trait Implementations§

Source§

impl Clone for OriginProxy

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OriginProxy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more