forwarded_header_value

Struct ForwardedHeaderValue

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

This structure represents the contents of the Forwarded header

It should contain one or more ForwardedStanzas

Implementations§

Source§

impl ForwardedHeaderValue

Source

pub fn len(&self) -> usize

The number of valid stanzas in this value

Source

pub fn is_empty(&self) -> bool

This can never be empty

Source

pub fn remotest(&self) -> &ForwardedStanza

Get the value farthest from this system (the left-most value)

This may represent the remote client

Source

pub fn into_remotest(self) -> ForwardedStanza

Get the value farthest from this system (the left-most value), consuming this object

This may represent the remote client

Source

pub fn proximate(&self) -> &ForwardedStanza

Get the value closest to this system (the right-most value).

This is typically the only trusted value in a well-architected system.

Source

pub fn into_proximate(self) -> ForwardedStanza

Get the value closest to this system (the right-most value), consuming this object

This is typically the only trusted value in a well-architected system.

Source

pub fn iter(&self) -> ForwardedHeaderValueIterator<'_>

Iterate through all ForwardedStanzas

Source

pub fn proximate_forwarded_for_ip(&self) -> Option<IpAddr>

Return the rightmost non-empty forwarded-for IP, if one is present

Source

pub fn remotest_forwarded_for_ip(&self) -> Option<IpAddr>

Return the leftmost forwarded-for IP, if one is present

Source

pub fn from_forwarded( header_value: &str, ) -> Result<Self, ForwardedHeaderValueParseError>

Parse the value from a Forwarded header into this structure

§Example
let input = "for=1.2.3.4;by=\"[::1]:1234\"";
let value = ForwardedHeaderValue::from_forwarded(input)?;
assert_eq!(value.len(), 1);
assert_eq!(value.remotest_forwarded_for_ip(), Some("1.2.3.4".parse()?));
Source

pub fn from_x_forwarded_for( header_value: &str, ) -> Result<Self, ForwardedHeaderValueParseError>

Parse the value from an X-Forwarded-For header into this structure

§Example
let input = "1.2.3.4, 5.6.7.8";
let value = ForwardedHeaderValue::from_x_forwarded_for(input)?;
assert_eq!(value.len(), 2);
assert_eq!(value.remotest_forwarded_for_ip(), Some("1.2.3.4".parse()?));
assert_eq!(value.proximate_forwarded_for_ip(), Some("5.6.7.8".parse()?));

Trait Implementations§

Source§

impl Debug for ForwardedHeaderValue

Source§

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

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

impl FromStr for ForwardedHeaderValue

Source§

type Err = ForwardedHeaderValueParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl IntoIterator for ForwardedHeaderValue

Source§

type Item = ForwardedStanza

The type of the elements being iterated over.
Source§

type IntoIter = Chain<Once<<ForwardedHeaderValue as IntoIterator>::Item>, IntoIter<<ForwardedHeaderValue as IntoIterator>::Item>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. 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, 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.