pub struct HeaderDecoder;
Expand description
PROXY Protocol v2 header decoder.
See decode
for more details.
Implementations§
Source§impl HeaderDecoder
impl HeaderDecoder
Sourcepub fn decode<'a>(buf: &'a [u8]) -> Result<Decoded<'a>, DecodeError>
pub fn decode<'a>(buf: &'a [u8]) -> Result<Decoded<'a>, DecodeError>
Try to decode the PROXY Protocol v2 header from the given buffer.
The caller SHOULD first peek exactly 12 bytes from the network
input into a buffer and decode
it, to detect the
presence of a 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 16 + remaining_bytes
bytes into a buffer (may reuse the buffer peeking
the MAGIC bytes) then decode
it.
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.