Skip to main content

XffChain

Struct XffChain 

Source
pub struct XffChain<'a> { /* private fields */ }
Expand description

A validated X-Forwarded-For chain.

§Examples

use parse_net::{forwarded::parse_x_forwarded_for, Limits};

let lines: [&[u8]; 1] = [b"203.0.113.9, 10.0.0.1:8080"];
let chain = parse_x_forwarded_for(&lines, &Limits::DEFAULT)?;
assert_eq!(chain.len(), 2);
assert_eq!(chain.iter().last(), Some(("10.0.0.1".parse()?, Some(8080))));

Implementations§

Source§

impl<'a> XffChain<'a>

Source

pub fn iter(&self) -> impl Iterator<Item = (IpAddr, Option<u16>)> + use<'a>

The addresses and ports, left to right across every line.

§Examples
use parse_net::{forwarded::parse_x_forwarded_for, Limits};

let lines: [&[u8]; 1] = [b"203.0.113.9, [2001:db8::1]:443"];
let mut it = parse_x_forwarded_for(&lines, &Limits::DEFAULT)?.iter();
assert_eq!(it.next(), Some(("203.0.113.9".parse()?, None)));
assert_eq!(it.next(), Some(("2001:db8::1".parse()?, Some(443))));
assert_eq!(it.next(), None);
Source

pub const fn len(&self) -> usize

The number of addresses.

§Examples
use parse_net::{forwarded::parse_x_forwarded_for, Limits};

let lines: [&[u8]; 2] = [b"203.0.113.9, 198.51.100.7", b"10.0.0.1"];
assert_eq!(parse_x_forwarded_for(&lines, &Limits::DEFAULT)?.len(), 3);
Source

pub const fn is_empty(&self) -> bool

Whether there are no addresses.

§Examples
use parse_net::{forwarded::parse_x_forwarded_for, Limits};

let none: [&[u8]; 0] = [];
assert!(parse_x_forwarded_for(&none, &Limits::DEFAULT)?.is_empty());
assert!(!parse_x_forwarded_for(&[&b"10.0.0.1"[..]], &Limits::DEFAULT)?.is_empty());

Trait Implementations§

Source§

impl<'a> Clone for XffChain<'a>

Source§

fn clone(&self) -> Self

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<'a> Copy for XffChain<'a>

Source§

impl<'a> Debug for XffChain<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Forget for XffChain<'a>

§

impl<'a> Freeze for XffChain<'a>

§

impl<'a> RefUnwindSafe for XffChain<'a>

§

impl<'a> Send for XffChain<'a>

§

impl<'a> Sync for XffChain<'a>

§

impl<'a> Unpin for XffChain<'a>

§

impl<'a> UnsafeUnpin for XffChain<'a>

§

impl<'a> UnwindSafe for XffChain<'a>

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.