Skip to main content

HeaderBuilder

Struct HeaderBuilder 

Source
pub struct HeaderBuilder { /* private fields */ }
Expand description

Proxy Protocol header builder

Implementations§

Source§

impl HeaderBuilder

Source

pub fn v2_proxy(source: SocketAddr, destination: SocketAddr) -> Self

Create a v2 PROXY header with source and destination addresses

§Panics

Panics if source and destination have different address families (e.g. one IPv4 and one IPv6)

Source

pub fn v2_local() -> Self

Create a v2 LOCAL header (health-check / proxy-to-self)

Source

pub fn v1_proxy(source: SocketAddr, destination: SocketAddr) -> Self

Create a v1 PROXY header with source and destination addresses

§Panics

Panics if source and destination have different address families

Source

pub fn v1_unknown() -> Self

Create a v1 UNKNOWN header (no addresses)

Source

pub fn v2_unix( source: impl Into<Vec<u8>>, destination: impl Into<Vec<u8>>, protocol: TransportProtocol, ) -> Self

Create a v2 PROXY header for Unix domain sockets

Source

pub fn with_transport_protocol(self, protocol: TransportProtocol) -> Self

Override the transport protocol (default is Stream for inet headers)

Source

pub fn with_authority(self, authority: impl Into<String>) -> Self

Add an authority TLV (0x02)

Source

pub fn with_unique_id(self, id: impl Into<Vec<u8>>) -> Self

Add a unique ID TLV (0x05)

§Panics

Panics if id exceeds 128 bytes (the spec maximum for PP2_TYPE_UNIQUE_ID)

Source

pub fn with_alpn(self, alpn: impl Into<Vec<u8>>) -> Self

Add an ALPN TLV (0x01)

Source

pub fn with_ssl(self, ssl: SslInfo) -> Self

Add an SSL info TLV (0x20)

Source

pub fn with_netns(self, netns: impl Into<String>) -> Self

Add a NETNS TLV (0x30)

Source

pub fn with_raw_tlv(self, type_byte: u8, value: impl Into<Vec<u8>>) -> Self

Add an arbitrary raw TLV

Source

pub fn with_padding(self, len: u16) -> Self

Add a NOOP padding TLV (0x04) with len zero bytes

Source

pub fn with_crc32c(self) -> Self

Enable CRC32c checksum TLV; the checksum is computed at build time

Source

pub fn build(&self) -> Vec<u8>

Encode the header to bytes

§Panics

Panics if any single TLV value exceeds 65 535 bytes or if the total v2 payload (addresses + all TLVs) exceeds 65 535 bytes. These are hard limits of the v2 wire format (u16 length fields).

Source

pub async fn write_to<W: AsyncWrite + Unpin>( &self, writer: &mut W, ) -> Result<usize>

Write the header directly to an AsyncWrite sink

§Panics

Same as build(): panics if any TLV value or the total v2 payload exceeds the 65 535-byte protocol limit.

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.