Struct forwarded_header_value::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

§

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

§

type Item = ForwardedStanza

The type of the elements being iterated over.
§

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>,

§

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>,

§

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.