Struct HttpUpgradeMitmRelayExtensions
pub struct HttpUpgradeMitmRelayExtensions(pub Extensions);http and std only.Expand description
Message-local metadata selected for an HTTP MITM upgrade.
Request matchers can insert this on the matched request to transfer values
to the upgraded ingress stream. Response matchers and middleware can insert
it on the response to transfer values to the upgraded egress stream.
HttpUpgradeMitmRelay transfers these values
only after both upgrades succeed, before calling the relay service.
The relay reserves a shared response-local selection before returning the
response, so outer response middleware can append values before the server
completes the ingress upgrade. Use self_get_ref_or_insert(Self::default)
to extend an existing selection instead of replacing its marker.
Only a message’s own marker is used: a response must not inherit the
request’s selection through its extension parent chain. The payload should
contain independently owned metadata, never the message’s extensions or
its structural Ingress, Egress, or OnUpgrade state. In particular,
snapshots of HTTP parts should have empty extensions to avoid ownership
cycles and retaining resources from the HTTP exchange.
§Selecting response metadata
To make response metadata available to the upgraded egress transport, insert it into this selection. Store it on the HTTP response as well when HTTP middleware needs access to the same value:
use rama_core::extensions::{Extension, ExtensionsRef};
use rama_http::{Response, layer::upgrade::mitm::HttpUpgradeMitmRelayExtensions};
#[derive(Debug, Clone, Extension)]
struct NegotiatedProtocol(&'static str);
let response = Response::new(());
let protocol = NegotiatedProtocol("chat");
// Keep the value on the HTTP response if HTTP middleware also needs it.
response.extensions().insert(protocol.clone());
// Append to the shared selection, including when an inner relay reserved it.
let selected = &response
.extensions()
.self_get_ref_or_insert(HttpUpgradeMitmRelayExtensions::default)
.0;
selected.insert(protocol);Use the same pattern on a matched request for ingress metadata. Always use the local lookup shown here so a response cannot reuse its request’s selection through the extension parent chain.
Tuple Fields§
§0: ExtensionsTrait Implementations§
§impl Clone for HttpUpgradeMitmRelayExtensions
impl Clone for HttpUpgradeMitmRelayExtensions
§fn clone(&self) -> HttpUpgradeMitmRelayExtensions
fn clone(&self) -> HttpUpgradeMitmRelayExtensions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for HttpUpgradeMitmRelayExtensions
impl Debug for HttpUpgradeMitmRelayExtensions
§impl Default for HttpUpgradeMitmRelayExtensions
impl Default for HttpUpgradeMitmRelayExtensions
§fn default() -> HttpUpgradeMitmRelayExtensions
fn default() -> HttpUpgradeMitmRelayExtensions
impl Extension for HttpUpgradeMitmRelayExtensions
Auto Trait Implementations§
impl Freeze for HttpUpgradeMitmRelayExtensions
impl RefUnwindSafe for HttpUpgradeMitmRelayExtensions
impl Send for HttpUpgradeMitmRelayExtensions
impl Sync for HttpUpgradeMitmRelayExtensions
impl Unpin for HttpUpgradeMitmRelayExtensions
impl UnsafeUnpin for HttpUpgradeMitmRelayExtensions
impl UnwindSafe for HttpUpgradeMitmRelayExtensions
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
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,
§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