Struct Forwarded

Source
pub struct Forwarded<'fe> {
    pub elements: Vec<ForwardedElement<'fe>>,
}
Expand description

A Rust representation of the RFC 7329 Forwarded production.

Fields§

§elements: Vec<ForwardedElement<'fe>>

Ordered vector of forwarded-element.

Implementations§

Source§

impl<'fe, 'input: 'fe> Forwarded<'fe>

Source

pub fn new() -> Self

Builds a new Forwarded.

Source

pub fn from_headers( headers: &'input impl AsRef<Headers>, ) -> Result<Option<Self>, ForwardedError>

Parse a list of Forwarded HTTP headers into a borrowed Forwarded instance, with X-Forwarded-* fallback.

§Fallback behaviour

If no Forwarded HTTP header was set it falls back to trying to parse one of the supported kinds of X-Forwarded-* headers. See from_x_forwarded_headers for more information.

§Examples
let mut request = Request::new(Get, Url::parse("http://_/")?);
request.insert_header("X-Forwarded-For", "198.51.100.46");
request.insert_header(
    "Forwarded",
    r#"for=192.0.2.43, for="[2001:db8:cafe::17]", for=unknown;proto=https"#
);
let forwarded = Forwarded::from_headers(&request)?.unwrap();
//assert_eq!(forwarded.to_string(), r#"for=192.0.2.43, for="[2001:db8:cafe::17]", for=unknown;proto=https"#);
let mut request = Request::new(Get, Url::parse("http://_/")?);
request.insert_header("X-Forwarded-For", "192.0.2.43, 2001:db8:cafe::17, unknown");
let forwarded = Forwarded::from_headers(&request)?.unwrap();
assert_eq!(forwarded.to_string(), r#"for=192.0.2.43, for="[2001:db8:cafe::17]", for=unknown"#);
let mut request = Request::new(Get, Url::parse("http://_/")?);
request.insert_header("X-Forwarded-For", "192.0.2.43, 2001:db8:cafe::17, unknown");
request.insert_header("X-Forwarded-Proto", "https");
assert_eq!(
    Forwarded::from_headers(&request),
    Err(ForwardedError::MultipleXForwardedHeaders(vec![
        "x-forwarded-for".to_string(),
        "x-forwarded-proto".to_string()
    ])),
);
Source

pub fn from_forwarded_header( headers: &'input impl AsRef<Headers>, ) -> Result<Option<Self>, ForwardedError>

Parses list of Forwarded HTTP headers into a borrowed Forwarded instance.

Source

pub fn from_x_forwarded_headers( headers: &'input impl AsRef<Headers>, ) -> Result<Option<Self>, ForwardedError>

Attempt to parse non-standard X-Forwarded-* headers into a borrowed Forwarded instance.

This will only attempt to do the conversion if only one kind of X-Forwarded-* header was specified since there is no way for us to know which order the headers were added in and at which steps. This is in accordance with Section 7.4 of RFC 7239.

§Supported headers
  • X-Forwarded-By
  • X-Forwarded-For
  • X-Forwarded-Host
  • X-Forwarded-Proto
Source

pub fn parse( &mut self, input: &'input str, ) -> Result<&'input str, ForwardedError>

Parses a Forwarded HTTP header value into a borrowed Forwarded instance.

Source

pub fn into_owned(self) -> Forwarded<'static>

Transform a borrowed Forwarded into an owned Forwarded.

Trait Implementations§

Source§

impl<'fe> Clone for Forwarded<'fe>

Source§

fn clone(&self) -> Forwarded<'fe>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'fe> Debug for Forwarded<'fe>

Source§

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

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

impl<'fe> Default for Forwarded<'fe>

Source§

fn default() -> Forwarded<'fe>

Returns the “default value” for a type. Read more
Source§

impl<'fe> Display for Forwarded<'fe>

Source§

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

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

impl<'input> Header for Forwarded<'input>

Source§

fn header_name(&self) -> HeaderName

Access the header’s name.
Source§

fn header_value(&self) -> HeaderValue

Access the header’s value.
Source§

fn apply_header<H: AsMut<Headers>>(&self, headers: H)

Insert the header name and header value into something that looks like a Headers map.
Source§

impl<'fe> PartialEq for Forwarded<'fe>

Source§

fn eq(&self, other: &Forwarded<'fe>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'fe> Eq for Forwarded<'fe>

Source§

impl<'fe> StructuralPartialEq for Forwarded<'fe>

Auto Trait Implementations§

§

impl<'fe> Freeze for Forwarded<'fe>

§

impl<'fe> RefUnwindSafe for Forwarded<'fe>

§

impl<'fe> Send for Forwarded<'fe>

§

impl<'fe> Sync for Forwarded<'fe>

§

impl<'fe> Unpin for Forwarded<'fe>

§

impl<'fe> UnwindSafe for Forwarded<'fe>

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToHeaderValues for T
where T: Header,

Source§

type Iter = IntoIter<HeaderValue>

Returned iterator over header values which this type may correspond to.
Source§

fn to_header_values(&self) -> Result<<T as ToHeaderValues>::Iter, Error>

Converts this object to an iterator of resolved HeaderValues.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,