Struct HaProxyLayer
pub struct HaProxyLayer<P = Tcp, V = Two> { /* private fields */ }haproxy only.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§
§impl HaProxyLayer
impl HaProxyLayer
pub fn tcp() -> HaProxyLayer
pub fn tcp() -> HaProxyLayer
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)
pub 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.
§impl HaProxyLayer<Udp>
impl HaProxyLayer<Udp>
pub fn udp() -> HaProxyLayer<Udp>
pub fn udp() -> HaProxyLayer<Udp>
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)
§impl<P> HaProxyLayer<P>
impl<P> HaProxyLayer<P>
pub fn with_payload(self, payload: impl Into<Bytes>) -> HaProxyLayer<P>
pub fn with_payload(self, payload: impl Into<Bytes>) -> HaProxyLayer<P>
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.
pub fn set_payload(&mut self, payload: impl Into<Bytes>) -> &mut HaProxyLayer<P>
pub fn set_payload(&mut self, payload: impl Into<Bytes>) -> &mut HaProxyLayer<P>
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.
pub fn with_tlv(self, kind: Type, value: impl Into<Bytes>) -> HaProxyLayer<P>
pub fn with_tlv(self, kind: Type, value: impl Into<Bytes>) -> HaProxyLayer<P>
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.
pub fn set_tlv(
&mut self,
kind: Type,
value: impl Into<Bytes>,
) -> &mut HaProxyLayer<P>
pub fn set_tlv( &mut self, kind: Type, value: impl Into<Bytes>, ) -> &mut HaProxyLayer<P>
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.
pub fn with_crc32c(self, enabled: bool) -> HaProxyLayer<P>
pub fn with_crc32c(self, enabled: bool) -> HaProxyLayer<P>
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.
pub fn set_crc32c(&mut self, enabled: bool) -> &mut HaProxyLayer<P>
pub fn set_crc32c(&mut self, enabled: bool) -> &mut HaProxyLayer<P>
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§
§impl<P, V> Clone for HaProxyLayer<P, V>
impl<P, V> Clone for HaProxyLayer<P, V>
§fn clone(&self) -> HaProxyLayer<P, V>
fn clone(&self) -> HaProxyLayer<P, V>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<P, V> Debug for HaProxyLayer<P, V>
impl<P, V> Debug for HaProxyLayer<P, V>
§impl<S, P, V> Layer<S> for HaProxyLayer<P, V>where
V: Clone,
impl<S, P, V> Layer<S> for HaProxyLayer<P, V>where
V: Clone,
§type Service = HaProxyService<S, P, V>
type Service = HaProxyService<S, P, V>
§fn layer(&self, inner: S) -> <HaProxyLayer<P, V> as Layer<S>>::Service
fn layer(&self, inner: S) -> <HaProxyLayer<P, V> as Layer<S>>::Service
§fn into_layer(self, inner: S) -> <HaProxyLayer<P, V> as Layer<S>>::Service
fn into_layer(self, inner: S) -> <HaProxyLayer<P, V> as Layer<S>>::Service
layer but consuming self after the service was created. Read moreAuto Trait Implementations§
impl<P, V> Freeze for HaProxyLayer<P, V>where
V: Freeze,
impl<P, V> RefUnwindSafe for HaProxyLayer<P, V>where
V: RefUnwindSafe,
impl<P, V> Send for HaProxyLayer<P, V>where
V: Send,
impl<P, V> Sync for HaProxyLayer<P, V>where
V: Sync,
impl<P, V> Unpin for HaProxyLayer<P, V>where
V: Unpin,
impl<P, V> UnsafeUnpin for HaProxyLayer<P, V>where
V: UnsafeUnpin,
impl<P, V> UnwindSafe for HaProxyLayer<P, V>where
V: UnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>
§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writer§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writer§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writer§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writer§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer