pub struct TrustedProxyConfig { /* private fields */ }Expand description
Which peers are trusted to set Forwarded/X-Forwarded-For, how many
hops into the chain to trust when they are, and which of the two
headers to honor.
Applied by the consumer as a plain Extension<TrustedProxyConfig>
(.layer(Extension(config))) on every router the app serves —
resolved inline inside crate::headers::enrich_context_from_headers
rather than through a bespoke tower::Layer/Service pair (Option A’,
docs/design/trusted-proxy-client-ip.md).
The default (TrustedProxyConfig::none, and the behavior when no
Extension is applied at all) trusts nothing: Forwarded/
X-Forwarded-For are never honored. enrich_context_from_headers
falls back to the verified socket peer address (via
axum::extract::ConnectInfo<SocketAddr>) when one is available, or
records no client_ip at all when it isn’t — never guessing, never
trusting an unverified header. See decision 3 in the design doc.
Implementations§
Source§impl TrustedProxyConfig
impl TrustedProxyConfig
Sourcepub fn none() -> TrustedProxyConfig
pub fn none() -> TrustedProxyConfig
Trust nothing. Equivalent to omitting the Extension entirely —
provided as an explicit, self-documenting constructor for callers
who want to state the choice rather than rely on absence.
Sourcepub fn trusting(
allowlist: impl IntoIterator<Item = IpNet>,
) -> TrustedProxyConfig
pub fn trusting( allowlist: impl IntoIterator<Item = IpNet>, ) -> TrustedProxyConfig
Trust the given peers (exact host addresses or CIDR ranges) as
reverse proxies. max_hops defaults to 1 (a single trusted
proxy) — call Self::max_hops to widen it for a chain of
several trusted proxies (e.g. CDN + load balancer, both
configured here). The forwarding header defaults to
ForwardedHeader::XForwardedFor — call Self::forwarded_header
if the deployment’s proxy actually emits RFC 7239 Forwarded
instead.
A bare host address can be supplied via IpAddr’s Into<IpNet>
impl (a full-length /32 or /128 prefix): IpAddr::from(...).into().
Sourcepub fn max_hops(self, max_hops: usize) -> TrustedProxyConfig
pub fn max_hops(self, max_hops: usize) -> TrustedProxyConfig
How many entries, counted from the right (proxy) end of the
Forwarded/X-Forwarded-For chain, are trusted to have been
appended by a trusted proxy.
This must be interpreted right-to-left: the entry taken is the
one max_hops positions in from the right end, not the
max_hops-th entry from the left. The left end of the chain is
exactly the part an untrusted client controls — walking from the
left re-opens the spoofing gap this type exists to close for any
chain with more than one hop. See decision 5 in
docs/design/trusted-proxy-client-ip.md.
Sourcepub fn forwarded_header(self, header: ForwardedHeader) -> TrustedProxyConfig
pub fn forwarded_header(self, header: ForwardedHeader) -> TrustedProxyConfig
Select which single header this deployment’s trusted proxy writes.
See ForwardedHeader’s doc for why only one is ever honored.
Sourcepub fn is_trusted(&self, peer: IpAddr) -> bool
pub fn is_trusted(&self, peer: IpAddr) -> bool
Whether peer — the verified socket peer address, never a
client-suppliable value — is a configured trusted proxy.
Trait Implementations§
Source§impl Clone for TrustedProxyConfig
impl Clone for TrustedProxyConfig
Source§fn clone(&self) -> TrustedProxyConfig
fn clone(&self) -> TrustedProxyConfig
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 TrustedProxyConfig
impl Debug for TrustedProxyConfig
Source§impl Default for TrustedProxyConfig
impl Default for TrustedProxyConfig
Source§fn default() -> TrustedProxyConfig
fn default() -> TrustedProxyConfig
Auto Trait Implementations§
impl Freeze for TrustedProxyConfig
impl RefUnwindSafe for TrustedProxyConfig
impl Send for TrustedProxyConfig
impl Sync for TrustedProxyConfig
impl Unpin for TrustedProxyConfig
impl UnsafeUnpin for TrustedProxyConfig
impl UnwindSafe for TrustedProxyConfig
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,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more§impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<T> OrderedSeq<'_, T> for Twhere
T: Clone,
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§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();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§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();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§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();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§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();§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.
§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);§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
§type Iter<'a> = Once<&'a T>
where
T: 'a
type Iter<'a> = Once<&'a T> where T: 'a
§fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
§fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
MaybeRef].