pub struct HaProxyLayer<P = Tcp, V = Two> { /* private fields */ }Expand description
Layer to encode and write the HaProxy Protocol, as a client on the connected stream.
This connector should in most cases happen as the first thing after establishing the connection.
Implementations§
Source§impl HaProxyLayer
impl HaProxyLayer
Sourcepub fn tcp() -> Self
pub fn tcp() -> Self
Create a new HaProxyLayer for the TCP protocol (default).
This is in the PROXY spec referred to as:
- TCP4 (for IPv4, v1)
- TCP6 (for IPv6, v1)
- Stream (v2)
Sourcepub fn v1(self) -> HaProxyLayer<Tcp, One>
pub fn v1(self) -> HaProxyLayer<Tcp, One>
Use version one of PROXY protocol, instead of the default version two.
Version one makes use of a less advanced text protocol, instead the more advanced binary v2 protocol.
Use this only if you have no control over a v1-only server.
Source§impl HaProxyLayer<Udp>
impl HaProxyLayer<Udp>
Sourcepub fn udp() -> Self
pub fn udp() -> Self
Create a new HaProxyLayer for the UDP protocol,
instead of the default TCP protocol.
This is in the PROXY spec referred to as:
- Datagram (v2)
Source§impl<P> HaProxyLayer<P>
impl<P> HaProxyLayer<P>
Sourcepub fn with_payload(self, payload: impl Into<Bytes>) -> Self
pub fn with_payload(self, payload: impl Into<Bytes>) -> Self
Attach a raw bytes payload to the PROXY v2 header, written verbatim after the address block.
Wire-format hazard. Spec section 2.2 says everything after the
address block is a sequence of TLVs. If your bytes are not valid
TLV encoding, conforming receivers (including rama’s server) will
either reject the connection or mis-parse the data. Prefer
[Self::tlv] for anything spec-compliant; treat payload as a
raw escape hatch for testing.
In particular, combining payload with [Self::crc32c] is
rejected at send time: the CRC32C TLV would be appended after
the raw payload, which means the receiver would try to interpret
the payload as TLVs, fail, and the CRC would be computed over a
header the receiver can’t validate. Use TLVs instead.
NOTE this is only possible in Version two of the PROXY Protocol.
In case you downgrade this HaProxyLayer to version one later
using Self::v1 this payload will be dropped.
Sourcepub fn set_payload(&mut self, payload: impl Into<Bytes>) -> &mut Self
pub fn set_payload(&mut self, payload: impl Into<Bytes>) -> &mut Self
Attach a raw bytes payload to the PROXY v2 header, written verbatim after the address block.
Wire-format hazard. Spec section 2.2 says everything after the
address block is a sequence of TLVs. If your bytes are not valid
TLV encoding, conforming receivers (including rama’s server) will
either reject the connection or mis-parse the data. Prefer
[Self::tlv] for anything spec-compliant; treat payload as a
raw escape hatch for testing.
In particular, combining payload with [Self::crc32c] is
rejected at send time: the CRC32C TLV would be appended after
the raw payload, which means the receiver would try to interpret
the payload as TLVs, fail, and the CRC would be computed over a
header the receiver can’t validate. Use TLVs instead.
NOTE this is only possible in Version two of the PROXY Protocol.
In case you downgrade this HaProxyLayer to version one later
using Self::v1 this payload will be dropped.
Sourcepub fn with_tlv(self, kind: Type, value: impl Into<Bytes>) -> Self
pub fn with_tlv(self, kind: Type, value: impl Into<Bytes>) -> Self
Attach a Type-Length-Value entry to the emitted v2 header.
Call this once per TLV; entries are written in insertion order.
Queuing a v2::Type::CRC32C entry here is rejected at send
time — a CRC value must be computed over the final header bytes,
so use [Self::crc32c] instead.
NOTE this is only possible in Version two of the PROXY Protocol.
On downgrade to v1 via Self::v1 all TLVs are dropped.
Sourcepub fn set_tlv(&mut self, kind: Type, value: impl Into<Bytes>) -> &mut Self
pub fn set_tlv(&mut self, kind: Type, value: impl Into<Bytes>) -> &mut Self
Attach a Type-Length-Value entry to the emitted v2 header.
Call this once per TLV; entries are written in insertion order.
Queuing a v2::Type::CRC32C entry here is rejected at send
time — a CRC value must be computed over the final header bytes,
so use [Self::crc32c] instead.
NOTE this is only possible in Version two of the PROXY Protocol.
On downgrade to v1 via Self::v1 all TLVs are dropped.
Sourcepub fn with_crc32c(self, enabled: bool) -> Self
pub fn with_crc32c(self, enabled: bool) -> Self
Toggle automatic emission of a valid PP2_TYPE_CRC32C TLV.
When enabled, the CRC is computed over the final header (with the CRC field zeroed during computation, per spec section 2.2.5) and appended as the last TLV. Receivers that enforce CRC verification (rama’s server default) will accept the header.
Incompatible with [Self::payload]: setting both is rejected at
send time because the raw payload would sit between the TLVs and
the CRC32C TLV, which standards-conforming receivers cannot parse.
NOTE this is only possible in Version two of the PROXY Protocol.
Sourcepub fn set_crc32c(&mut self, enabled: bool) -> &mut Self
pub fn set_crc32c(&mut self, enabled: bool) -> &mut Self
Toggle automatic emission of a valid PP2_TYPE_CRC32C TLV.
When enabled, the CRC is computed over the final header (with the CRC field zeroed during computation, per spec section 2.2.5) and appended as the last TLV. Receivers that enforce CRC verification (rama’s server default) will accept the header.
Incompatible with [Self::payload]: setting both is rejected at
send time because the raw payload would sit between the TLVs and
the CRC32C TLV, which standards-conforming receivers cannot parse.
NOTE this is only possible in Version two of the PROXY Protocol.
Trait Implementations§
Source§impl<S, P, V: Clone> Layer<S> for HaProxyLayer<P, V>
impl<S, P, V: Clone> Layer<S> for HaProxyLayer<P, V>
Source§type Service = HaProxyService<S, P, V>
type Service = HaProxyService<S, P, V>
Source§fn layer(&self, inner: S) -> Self::Service
fn layer(&self, inner: S) -> Self::Service
Source§fn into_layer(self, inner: S) -> Self::Service
fn into_layer(self, inner: S) -> Self::Service
layer but consuming self after the service was created. Read moreAuto Trait Implementations§
impl<P, V> Freeze for HaProxyLayer<P, V>
impl<P, V> RefUnwindSafe for HaProxyLayer<P, V>
impl<P, V> Send for HaProxyLayer<P, V>
impl<P, V> Sync for HaProxyLayer<P, V>
impl<P, V> Unpin for HaProxyLayer<P, V>
impl<P, V> UnsafeUnpin for HaProxyLayer<P, V>
impl<P, V> UnwindSafe for HaProxyLayer<P, V>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more