Skip to main content

HttpAcl

Struct HttpAcl 

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

Represents an HTTP ACL.

Built via HttpAcl::builder (an HttpAclBuilder) rather than constructed directly. Once built, an HttpAcl is immutable; the various is_*_allowed methods check a single aspect of a request (scheme, method, host, port, IP, header, or URL path) and return an AclClassification. See the module-level documentation for how allow-lists, deny-lists, and per-category defaults combine.

Implementations§

Source§

impl HttpAcl

Source

pub fn builder() -> HttpAclBuilder

Returns a new HttpAclBuilder.

Source

pub fn is_scheme_allowed(&self, scheme: &str) -> AclClassification

Returns whether the scheme is allowed.

Unlike the other is_*_allowed methods, this is a plain per-scheme flag (set via HttpAclBuilder::http/HttpAclBuilder::https) rather than an allow/deny/default check, so it only ever returns AclClassification::AllowedUserAcl or AclClassification::DeniedUserAcl. Any scheme other than "http"/"https" is denied.

Source

pub fn is_method_allowed( &self, method: impl Into<HttpRequestMethod>, ) -> AclClassification

Returns whether the method is allowed.

Note: If you pass a string ensure it is uppercased first.

Source

pub fn is_host_allowed(&self, host: &str) -> AclClassification

Returns whether the host is allowed.

Hosts may be exact hostnames or wildcard patterns (see HttpAclBuilder::add_allowed_host for the wildcard syntax).

Note: The host should be in its canonical form (lowercase, punycode for IDN).

Source

pub fn is_port_allowed(&self, port: u16) -> AclClassification

Returns whether the port is allowed.

Source

pub fn is_ip_allowed(&self, ip: &IpAddr) -> AclClassification

Returns whether an IP is allowed.

A non-global IP (private, loopback, link-local, and other special-use addresses) is denied with AclClassification::DeniedNotGlobal before the allow/deny lists are even checked, unless HttpAclBuilder::non_global_ip_ranges was set to true.

Source

pub fn resolve_static_dns_mapping(&self, host: &str) -> Option<SocketAddr>

Resolve a static DNS mapping.

The returned address is still subject to the IP and port ACL - callers must check it with Self::is_ip_allowed and Self::is_port_allowed themselves. Use Self::resolve_trusted_static_dns_mapping for mappings that should bypass those checks entirely.

Note: The host should be in its canonical form (lowercase, punycode for IDN).

Source

pub fn resolve_trusted_static_dns_mapping( &self, host: &str, ) -> Option<SocketAddr>

Resolve a trusted static DNS mapping.

Unlike Self::resolve_static_dns_mapping, the returned address is meant to bypass the IP and port ACL entirely - only use this for mappings you trust regardless of what the ACL would otherwise say (e.g. pinning a hostname to an internal address on purpose).

Note: The host should be in its canonical form (lowercase, punycode for IDN).

Source

pub fn is_header_allowed( &self, header_name: &str, header_value: &str, ) -> AclClassification

Returns whether a header is allowed.

Note: Header names are case-insensitive, but this function assumes the caller provides them in a consistent case.

Source

pub fn is_url_path_allowed(&self, url_path: &str) -> AclClassification

Returns whether a URL path is allowed.

Note: The URL path should be percent-decoded before passing it to this function.

Source

pub fn is_valid<'h>( &self, scheme: &str, authority: &Authority, headers: impl Iterator<Item = (&'h str, &'h str)> + Send + Sync + 'h, body: Option<&[u8]>, ) -> AclClassification

Runs the ValidateFn attached to this ACL, if any, against a request.

Returns AclClassification::AllowedDefault when no ValidateFn was attached (the default for an HttpAcl built without one), so calling this is always safe even if you never configured custom validation.

Source

pub fn has_modify_request(&self) -> bool

Returns whether a ModifyRequestFn is attached to this ACL.

Cheap (a single field read). Check this before doing any work to make a request’s body/headers available for mutation (e.g. buffering a streaming body), so that omitting a ModifyRequestFn costs nothing at request time.

Source

pub fn has_modify_response(&self) -> bool

Returns whether a ModifyResponseFn is attached to this ACL.

See Self::has_modify_request - same rationale, for the response side.

Source

pub fn modify_request( &self, scheme: &str, authority: &Authority, mutation: &mut RequestMutation, )

Runs the ModifyRequestFn attached to this ACL, if any, against mutation, mutating it in place.

Does nothing when no ModifyRequestFn was attached, so calling this is always safe even if you never configured one - though see Self::has_modify_request if you want to skip preparing mutation at all in that case.

Source

pub fn modify_response( &self, scheme: &str, authority: &Authority, mutation: &mut ResponseMutation, )

Runs the ModifyResponseFn attached to this ACL, if any, against mutation, mutating it in place. See Self::modify_request.

Trait Implementations§

Source§

impl Clone for HttpAcl

Source§

fn clone(&self) -> HttpAcl

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 HttpAcl

Source§

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

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

impl Default for HttpAcl

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for HttpAcl

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. 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, 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> 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 = 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.