Skip to main content

NetworkResolver

Struct NetworkResolver 

Source
pub struct NetworkResolver { /* private fields */ }
Expand description

HTTPS-fetching resolver. Hardened by default with multiple SSRF and amplification defenses; the constructor requires a host allowlist so there’s no convenient “any host” mode.

Defaults:

  • HTTPS only (use [with_plaintext_http] to allow http://)
  • Refuses URLs whose resolved IP is RFC 1918 / loopback / link-local (use [with_private_ips_allowed] to disable)
  • 10-second per-request timeout
  • 1 MB max response size
  • 64 MB in-memory LRU cache (per resolver instance)

Implementations§

Source§

impl NetworkResolver

Source

pub fn new<I>(allowed_hosts: I) -> NetworkResolver
where I: IntoIterator<Item = String>,

Construct with the required host allowlist. Hosts are matched exactly (no wildcards) against the URL’s host component. All other settings get safe defaults; use the with_* builders to relax them.

Source

pub fn with_plaintext_http(self) -> NetworkResolver

Allow http:// URLs (default: HTTPS-only). Almost always wrong; use only for testing or air-gapped networks where TLS isn’t available.

Source

pub fn with_private_ips_allowed(self) -> NetworkResolver

Allow URLs whose resolved IP is RFC 1918 private, loopback, or link-local (default: refused for SSRF defense). Disable only if your allowed_hosts list already constrains to trusted internal hosts.

Source

pub fn with_max_response_bytes(self, n: usize) -> NetworkResolver

Source

pub fn with_timeout(self, d: Duration) -> NetworkResolver

Source

pub fn with_cache_size(self, max_total_bytes: usize) -> NetworkResolver

Trait Implementations§

Source§

impl Debug for NetworkResolver

Source§

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

Formats the value using the given formatter. Read more
Source§

impl EntityResolver for NetworkResolver

Source§

fn resolve( &self, _public_id: Option<&str>, system_id: &str, _base_uri: Option<&str>, ) -> Result<Vec<u8>, ResolveError>

Resolve an external entity reference. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.