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