Struct proxy_header::ProxyHeader
source · pub struct ProxyHeader<'a>(/* private fields */);
Expand description
A PROXY protocol header
Implementations§
source§impl<'a> ProxyHeader<'a>
impl<'a> ProxyHeader<'a>
sourcepub fn with_local() -> Self
pub fn with_local() -> Self
Create a new PROXY protocol header (local mode)
sourcepub fn with_address(addr: ProxiedAddress) -> Self
pub fn with_address(addr: ProxiedAddress) -> Self
Create a new PROXY protocol header (proxied mode)
sourcepub fn with_tlvs<'b>(
addr: Option<ProxiedAddress>,
tlvs: impl IntoIterator<Item = Tlv<'b>>,
) -> Self
pub fn with_tlvs<'b>( addr: Option<ProxiedAddress>, tlvs: impl IntoIterator<Item = Tlv<'b>>, ) -> Self
Create a new PROXY protocol header with the given TLV fields
use proxy_header::{ProxyHeader, ProxiedAddress, Tlv, Protocol, SslInfo};
let addrs = ProxiedAddress::stream(
"[2001:db8::1:1]:51234".parse().unwrap(),
"[2001:db8::2:1]:443".parse().unwrap()
);
let header = ProxyHeader::with_tlvs(
Some(addrs), [
Tlv::Authority("example.com".into()),
Tlv::Ssl(SslInfo::new(true, false, false, 0)),
]
);
println!("{:?}", header);
sourcepub fn parse(buf: &'a [u8], config: ParseConfig) -> Result<(Self, usize), Error>
pub fn parse(buf: &'a [u8], config: ParseConfig) -> Result<(Self, usize), Error>
Attempt to parse a PROXY protocol header from the given buffer
Returns the parsed header and the number of bytes consumed from the buffer. If the header
is incomplete, returns Error::BufferTooShort
so more data can be read from the socket.
If the header is malformed or unsupported, returns Error::Invalid
.
This function will borrow the buffer for the lifetime of the returned header. If
you need to keep the header around for longer than the buffer, use ProxyHeader::into_owned
.
sourcepub fn proxied_address(&self) -> Option<&ProxiedAddress>
pub fn proxied_address(&self) -> Option<&ProxiedAddress>
Proxied address information
If None
, this indicates so-called “local” mode, where the connection is not proxied.
This is usually the case when the connection is initiated by the proxy itself, e.g. for
health checks.
sourcepub fn tlvs(&self) -> Tlvs<'_> ⓘ
pub fn tlvs(&self) -> Tlvs<'_> ⓘ
Iterator that yields all extension TLV (type-length-value) fields present in the header
See Tlv
for more information on the different types of TLV fields.
sourcepub fn alpn(&self) -> Option<&[u8]>
pub fn alpn(&self) -> Option<&[u8]>
Raw ALPN extension data
See Tlv::Alpn
for more information.
Authority - typically the hostname of the client (SNI)
See Tlv::Authority
for more information.
sourcepub fn crc32c(&self) -> Option<u32>
pub fn crc32c(&self) -> Option<u32>
CRC32c checksum of the address information
See Tlv::Crc32c
for more information.
sourcepub fn unique_id(&self) -> Option<&[u8]>
pub fn unique_id(&self) -> Option<&[u8]>
Unique ID of the connection
See Tlv::UniqueId
for more information.
sourcepub fn netns(&self) -> Option<&str>
pub fn netns(&self) -> Option<&str>
Network namespace
See Tlv::Netns
for more information.
sourcepub fn into_owned(self) -> ProxyHeader<'static>
pub fn into_owned(self) -> ProxyHeader<'static>
Returns an owned version of this struct
sourcepub fn append_tlv(&mut self, tlv: Tlv<'_>)
pub fn append_tlv(&mut self, tlv: Tlv<'_>)
Appends an additional TLV field
sourcepub fn encode_v1(&self, buf: &mut Vec<u8>) -> Result<(), Error>
pub fn encode_v1(&self, buf: &mut Vec<u8>) -> Result<(), Error>
Encode this PROXY protocol header into a Vec
in version 1 format.
Returns Error::V1UnsupportedTlv
if the header contains any TLV fields and
Error::V1UnsupportedProtocol
if the header contains a non-TCP protocol, as
version 1 PROXY protocol does not support either of these.
sourcepub fn encode_v2(&self, buf: &mut Vec<u8>) -> Result<(), Error>
pub fn encode_v2(&self, buf: &mut Vec<u8>) -> Result<(), Error>
Encode this PROXY protocol header into a Vec
in version 2 format.
sourcepub fn encode_to_slice_v1(&self, buf: &mut [u8]) -> Result<usize, Error>
pub fn encode_to_slice_v1(&self, buf: &mut [u8]) -> Result<usize, Error>
Encode this PROXY protocol header into an existing buffer in version 1 format.
If the buffer is too small to contain the entire header, returns Error::BufferTooShort
.
See ProxyHeader::encode_v1
for more information.
sourcepub fn encode_to_slice_v2(&self, buf: &mut [u8]) -> Result<usize, Error>
pub fn encode_to_slice_v2(&self, buf: &mut [u8]) -> Result<usize, Error>
Encode this PROXY protocol header into an existing buffer in version 2 format.
If the buffer is too small to contain the entire header, returns Error::BufferTooShort
.
See ProxyHeader::encode_v2
for more information.
Trait Implementations§
source§impl<'a> Clone for ProxyHeader<'a>
impl<'a> Clone for ProxyHeader<'a>
source§fn clone(&self) -> ProxyHeader<'a>
fn clone(&self) -> ProxyHeader<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ProxyHeader<'_>
impl Debug for ProxyHeader<'_>
source§impl<'a> Default for ProxyHeader<'a>
impl<'a> Default for ProxyHeader<'a>
source§fn default() -> ProxyHeader<'a>
fn default() -> ProxyHeader<'a>
source§impl<'a> PartialEq for ProxyHeader<'a>
impl<'a> PartialEq for ProxyHeader<'a>
impl<'a> Eq for ProxyHeader<'a>
impl<'a> StructuralPartialEq for ProxyHeader<'a>
Auto Trait Implementations§
impl<'a> Freeze for ProxyHeader<'a>
impl<'a> RefUnwindSafe for ProxyHeader<'a>
impl<'a> Send for ProxyHeader<'a>
impl<'a> Sync for ProxyHeader<'a>
impl<'a> Unpin for ProxyHeader<'a>
impl<'a> UnwindSafe for ProxyHeader<'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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)