pub struct Header { /* private fields */ }
Expand description
The PROXY Protocol v1 header.
Implementations§
Source§impl Header
impl Header
Sourcepub const fn new(address_pair: AddressPair) -> Self
pub const fn new(address_pair: AddressPair) -> Self
Creates a new PROXY Protocol v1 header.
Sourcepub const fn address_pair(self) -> AddressPair
pub const fn address_pair(self) -> AddressPair
Returns the address pair of the PROXY Protocol v1 header.
Sourcepub fn encode(&self) -> String
pub fn encode(&self) -> String
Encodes the PROXY Protocol v1 header into a string representation.
Sourcepub fn decode(header_bytes: &[u8]) -> Result<Decoded, DecodeError>
pub fn decode(header_bytes: &[u8]) -> Result<Decoded, DecodeError>
Try to decode the PROXY Protocol v1 header from the given buffer.
The caller SHOULD first peek exactly 5 bytes from the network
input into a buffer and decode
it, to detect the
presence of a PROXY Protocol v1 header.
When the buffer is not prefixed with PROXY Protocol v1 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 v1 header.
When a PROXY protocol v1 header is detected, Decoded::Partial
is
returned (this is what we expect, since we only have the MAGIC bytes
peeked). The caller SHOULD read from network input into a buffer (may
reuse the buffer peeking the MAGIC bytes) until the first \n
, then
decode
it. This method will reject bytes w/o CRLF, and
any trailing bytes after CRLF.
The caller MAY ensure that the length of the header_bytes
does not
exceed the MAXIMUM_LENGTH
.
When any error is returned, the caller SHOULD reject the connection.