pub struct TrustedProxiesBuilder { /* private fields */ }Expand description
Builder for a config that trusts proxies by CIDR.
A request is resolved from headers only when its socket peer IP matches one of the added CIDRs.
Implementations§
Source§impl TrustedProxiesBuilder
impl TrustedProxiesBuilder
Sourcepub fn proxy(self, cidr: IpCidr) -> Self
pub fn proxy(self, cidr: IpCidr) -> Self
Add a trusted proxy CIDR without a client IP header.
Requests from this CIDR are resolved from the chain headers.
Sourcepub fn proxy_with_client_ip_header(
self,
cidr: IpCidr,
header: Uncased<'static>,
) -> Self
pub fn proxy_with_client_ip_header( self, cidr: IpCidr, header: Uncased<'static>, ) -> Self
Add a trusted proxy CIDR with a client IP header.
Use this when the proxy writes the client address into one header that holds a single IP. Common examples are X-Real-IP, CF-Connecting-IP, and True-Client-IP.
The header is read only when the socket peer IP is inside this CIDR. If it is missing or unusable, the chain headers are still tried, so the proxy should also clear or overwrite the chain headers it does not set itself.
Sourcepub fn proxy_with_x_real_ip(self, cidr: IpCidr) -> Self
pub fn proxy_with_x_real_ip(self, cidr: IpCidr) -> Self
Add a trusted proxy CIDR that sends the X-Real-IP header.
This is a shortcut for Self::proxy_with_client_ip_header, and it fits Nginx-like setups that pass one client address in X-Real-IP.
Sourcepub fn proxy_rule(self, rule: TrustedProxyRule) -> Self
pub fn proxy_rule(self, rule: TrustedProxyRule) -> Self
Add one prepared trusted proxy rule.
Sourcepub fn proxies(self, rules: impl IntoIterator<Item = TrustedProxyRule>) -> Self
pub fn proxies(self, rules: impl IntoIterator<Item = TrustedProxyRule>) -> Self
Add several prepared trusted proxy rules.
Use this when the rules come from a config file or another runtime source.
Sourcepub fn chain_header_order(
self,
order: impl IntoIterator<Item = ChainHeader>,
) -> Self
pub fn chain_header_order( self, order: impl IntoIterator<Item = ChainHeader>, ) -> Self
Set the chain headers, and the order they are tried in.
Use ChainHeader::new for a custom comma-separated IP list header, and an empty iterator to read no chain header at all.
Sourcepub fn disable_chain_headers(self) -> Self
pub fn disable_chain_headers(self) -> Self
Read no chain header at all.
Use this when the proxy sets a client IP header and cannot clear the chain headers a client may send.
Sourcepub fn build(self) -> Result<ClientIpConfig, ClientIpConfigBuildError>
pub fn build(self) -> Result<ClientIpConfig, ClientIpConfigBuildError>
Build an immutable config.
CIDRs that use the same client IP header are merged into as few rules as possible. CIDRs that use different client IP headers must not overlap, because one socket peer IP would then mean two policies.
An IPv4-mapped IPv6 CIDR, such as ::ffff:10.0.0.0/120, is rewritten to its IPv4 form first, so TrustedProxyRule::cidr may report a different CIDR than the one that was added.
§Errors
Returns ClientIpConfigBuildError::OverlappingTrustedProxyRules when two rules cover a common address but do not agree on the client IP header.
Trait Implementations§
Source§impl Clone for TrustedProxiesBuilder
impl Clone for TrustedProxiesBuilder
Source§fn clone(&self) -> TrustedProxiesBuilder
fn clone(&self) -> TrustedProxiesBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TrustedProxiesBuilder
impl Debug for TrustedProxiesBuilder
Source§impl Default for TrustedProxiesBuilder
impl Default for TrustedProxiesBuilder
impl Eq for TrustedProxiesBuilder
Source§impl Hash for TrustedProxiesBuilder
impl Hash for TrustedProxiesBuilder
Source§impl PartialEq for TrustedProxiesBuilder
impl PartialEq for TrustedProxiesBuilder
impl StructuralPartialEq for TrustedProxiesBuilder
Auto Trait Implementations§
impl Freeze for TrustedProxiesBuilder
impl RefUnwindSafe for TrustedProxiesBuilder
impl Send for TrustedProxiesBuilder
impl Sync for TrustedProxiesBuilder
impl Unpin for TrustedProxiesBuilder
impl UnsafeUnpin for TrustedProxiesBuilder
impl UnwindSafe for TrustedProxiesBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);