Struct HeaderDecoder

Source
pub struct HeaderDecoder;
Expand description

PROXY Protocol v2 header decoder.

See decode for more details.

Implementations§

Source§

impl HeaderDecoder

Source

pub fn decode<'a>(buf: &'a [u8]) -> Result<Decoded<'a>, DecodeError>

Attempts to decode the PROXY Protocol v2 header from its bytes representation.

The caller MAY first peek exactly HEADER_SIZE bytes from the network input into a buffer and then decode it, to detect the presence of a PROXY Protocol v2 header. If less than 16 bytes are peeked, the caller MAY reject the connection, or treat the connection as a normal one w/o PROXY Protocol v2 header.

When the buffer is not prefixed with PROXY Protocol v2 header MAGIC, this method returns Decoded::None. The caller MAY reject the connection, or treat the connection as a normal one w/o PROXY Protocol v2 header.

When a PROXY protocol v2 header is detected, Decoded::Partial is returned (this is what we expect, since we only have the MAGIC bytes peeked). The caller SHOULD then read exactly HEADER_SIZE + remaining_bytes bytes into a buffer (may reuse the buffer peeking the MAGIC bytes) and decode it again.

When any error is returned, the caller SHOULD reject the connection.

When there’re extensions in the PROXY Protocol v2 header, the caller SHOULD read the extensions to check if they are malformed or not. See DecodedExtensions for more details.

Trait Implementations§

Source§

impl Debug for HeaderDecoder

Source§

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

Formats the value using the given formatter. 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.