pub struct Header<'a> {
pub header: Cow<'a, [u8]>,
pub version: Version,
pub command: Command,
pub protocol: Protocol,
pub addresses: Addresses,
}
Expand description
A proxy protocol version 2 header.
§Examples
use rama_haproxy::protocol::v2::{Addresses, AddressFamily, Command, Header, IPv4, ParseError, Protocol, PROTOCOL_PREFIX, Type, TypeLengthValue, Version};
let mut header = Vec::from(PROTOCOL_PREFIX);
header.extend([
0x21, 0x12, 0, 16, 127, 0, 0, 1, 192, 168, 1, 1, 0, 80, 1, 187, 4, 0, 1, 42
]);
let addresses: Addresses = IPv4::new([127, 0, 0, 1], [192, 168, 1, 1], 80, 443).into();
let expected = Header {
header: header.as_slice().into(),
version: Version::Two,
command: Command::Proxy,
protocol: Protocol::Datagram,
addresses
};
let actual = Header::try_from(header.as_slice()).unwrap();
assert_eq!(actual, expected);
assert_eq!(actual.tlvs().collect::<Vec<Result<TypeLengthValue<'_>, ParseError>>>(), vec![Ok(TypeLengthValue::new(Type::NoOp, &[42]))]);
Fields§
§header: Cow<'a, [u8]>
The underlying byte slice this Header
is built on.
version: Version
The version of the PROXY protocol.
command: Command
The command of the PROXY protocol.
protocol: Protocol
The protocol of the PROXY protocol.
addresses: Addresses
The source and destination addresses of the PROXY protocol.
Implementations§
Source§impl Header<'_>
impl Header<'_>
Sourcepub fn address_family(&self) -> AddressFamily
pub fn address_family(&self) -> AddressFamily
The AddressFamily
of this Header
.
Sourcepub fn address_bytes(&self) -> &[u8] ⓘ
pub fn address_bytes(&self) -> &[u8] ⓘ
The bytes of the address portion of the payload.
Sourcepub fn tlvs(&self) -> TypeLengthValues<'_> ⓘ
pub fn tlvs(&self) -> TypeLengthValues<'_> ⓘ
An Iterator
of TypeLengthValue
s.
Trait Implementations§
impl<'a> Eq for Header<'a>
impl<'a> StructuralPartialEq for Header<'a>
Auto Trait Implementations§
impl<'a> Freeze for Header<'a>
impl<'a> RefUnwindSafe for Header<'a>
impl<'a> Send for Header<'a>
impl<'a> Sync for Header<'a>
impl<'a> Unpin for Header<'a>
impl<'a> UnwindSafe for Header<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more