Struct proxy_header::ProxyHeader

source ·
pub struct ProxyHeader<'a>(/* private fields */);
Expand description

A PROXY protocol header

Implementations§

source§

impl<'a> ProxyHeader<'a>

source

pub fn with_local() -> Self

Create a new PROXY protocol header (local mode)

source

pub fn with_address(addr: ProxiedAddress) -> Self

Create a new PROXY protocol header (proxied mode)

source

pub fn with_tlvs<'b>( addr: Option<ProxiedAddress>, tlvs: impl IntoIterator<Item = Tlv<'b>>, ) -> Self

Create a new PROXY protocol header with the given TLV fields

use proxy_header::{ProxyHeader, ProxiedAddress, Tlv, Protocol, SslInfo};

let addrs = ProxiedAddress::stream(
    "[2001:db8::1:1]:51234".parse().unwrap(),
    "[2001:db8::2:1]:443".parse().unwrap()
);
let header = ProxyHeader::with_tlvs(
   Some(addrs), [
        Tlv::Authority("example.com".into()),
        Tlv::Ssl(SslInfo::new(true, false, false, 0)),
     ]
);

println!("{:?}", header);
source

pub fn parse(buf: &'a [u8], config: ParseConfig) -> Result<(Self, usize), Error>

Attempt to parse a PROXY protocol header from the given buffer

Returns the parsed header and the number of bytes consumed from the buffer. If the header is incomplete, returns Error::BufferTooShort so more data can be read from the socket.

If the header is malformed or unsupported, returns Error::Invalid.

This function will borrow the buffer for the lifetime of the returned header. If you need to keep the header around for longer than the buffer, use ProxyHeader::into_owned.

source

pub fn proxied_address(&self) -> Option<&ProxiedAddress>

Proxied address information

If None, this indicates so-called “local” mode, where the connection is not proxied. This is usually the case when the connection is initiated by the proxy itself, e.g. for health checks.

source

pub fn tlvs(&self) -> Tlvs<'_>

Iterator that yields all extension TLV (type-length-value) fields present in the header

See Tlv for more information on the different types of TLV fields.

source

pub fn alpn(&self) -> Option<&[u8]>

Raw ALPN extension data

See Tlv::Alpn for more information.

source

pub fn authority(&self) -> Option<&str>

Authority - typically the hostname of the client (SNI)

See Tlv::Authority for more information.

source

pub fn crc32c(&self) -> Option<u32>

CRC32c checksum of the address information

See Tlv::Crc32c for more information.

source

pub fn unique_id(&self) -> Option<&[u8]>

Unique ID of the connection

See Tlv::UniqueId for more information.

source

pub fn ssl(&self) -> Option<SslInfo<'_>>

SSL information

See Tlv::Ssl for more information.

source

pub fn netns(&self) -> Option<&str>

Network namespace

See Tlv::Netns for more information.

source

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

Returns an owned version of this struct

source

pub fn append_tlv(&mut self, tlv: Tlv<'_>)

Appends an additional TLV field

source

pub fn encode_v1(&self, buf: &mut Vec<u8>) -> Result<(), Error>

Encode this PROXY protocol header into a Vec in version 1 format.

Returns Error::V1UnsupportedTlv if the header contains any TLV fields and Error::V1UnsupportedProtocol if the header contains a non-TCP protocol, as version 1 PROXY protocol does not support either of these.

source

pub fn encode_v2(&self, buf: &mut Vec<u8>) -> Result<(), Error>

Encode this PROXY protocol header into a Vec in version 2 format.

source

pub fn encode_to_slice_v1(&self, buf: &mut [u8]) -> Result<usize, Error>

Encode this PROXY protocol header into an existing buffer in version 1 format.

If the buffer is too small to contain the entire header, returns Error::BufferTooShort.

See ProxyHeader::encode_v1 for more information.

source

pub fn encode_to_slice_v2(&self, buf: &mut [u8]) -> Result<usize, Error>

Encode this PROXY protocol header into an existing buffer in version 2 format.

If the buffer is too small to contain the entire header, returns Error::BufferTooShort.

See ProxyHeader::encode_v2 for more information.

Trait Implementations§

source§

impl<'a> Clone for ProxyHeader<'a>

source§

fn clone(&self) -> ProxyHeader<'a>

Returns a copy 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 Debug for ProxyHeader<'_>

source§

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

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

impl<'a> Default for ProxyHeader<'a>

source§

fn default() -> ProxyHeader<'a>

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

impl<'a> PartialEq for ProxyHeader<'a>

source§

fn eq(&self, other: &ProxyHeader<'a>) -> 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<'a> Eq for ProxyHeader<'a>

source§

impl<'a> StructuralPartialEq for ProxyHeader<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for ProxyHeader<'a>

§

impl<'a> RefUnwindSafe for ProxyHeader<'a>

§

impl<'a> Send for ProxyHeader<'a>

§

impl<'a> Sync for ProxyHeader<'a>

§

impl<'a> Unpin for ProxyHeader<'a>

§

impl<'a> UnwindSafe for ProxyHeader<'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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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

§

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.