pub struct RequestContext { /* private fields */ }Expand description
Low-cardinality request context shared by REST/RPC Tower layers.
Implementations§
Source§impl RequestContext
impl RequestContext
Sourcepub fn new(
service: impl Into<String>,
transport: &'static str,
route: impl Into<String>,
method: impl Into<String>,
) -> Self
pub fn new( service: impl Into<String>, transport: &'static str, route: impl Into<String>, method: impl Into<String>, ) -> Self
Creates a context from explicit low-cardinality parts.
Sourcepub fn from_http_headers(
service: Option<&str>,
method: impl Into<String>,
route: Option<&str>,
headers: &HeaderMap,
) -> Self
pub fn from_http_headers( service: Option<&str>, method: impl Into<String>, route: Option<&str>, headers: &HeaderMap, ) -> Self
Builds an HTTP request context from headers and a route pattern.
Sourcepub fn from_tonic_metadata(
service: impl Into<String>,
method: impl Into<String>,
metadata: &MetadataMap,
) -> Self
pub fn from_tonic_metadata( service: impl Into<String>, method: impl Into<String>, metadata: &MetadataMap, ) -> Self
Builds a gRPC request context from tonic metadata and a method pattern.
Sourcepub fn with_request_id(self, request_id: impl Into<String>) -> Self
pub fn with_request_id(self, request_id: impl Into<String>) -> Self
Sets a request id.
Sourcepub fn with_traceparent(self, traceparent: impl Into<String>) -> Self
pub fn with_traceparent(self, traceparent: impl Into<String>) -> Self
Sets a W3C traceparent and derives trace/span ids when valid.
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
Returns the request id.
Sourcepub fn traceparent(&self) -> Option<&str>
pub fn traceparent(&self) -> Option<&str>
Returns the traceparent.
Sourcepub fn inject_http_headers(
&self,
headers: &mut HeaderMap,
) -> Result<(), InvalidHeaderValue>
pub fn inject_http_headers( &self, headers: &mut HeaderMap, ) -> Result<(), InvalidHeaderValue>
Inserts context values into HTTP headers when they are missing.
Sourcepub fn inject_tonic_metadata(
&self,
metadata: &mut MetadataMap,
) -> Result<(), InvalidMetadataValue>
pub fn inject_tonic_metadata( &self, metadata: &mut MetadataMap, ) -> Result<(), InvalidMetadataValue>
Inserts context values into tonic metadata when they are missing.
Sourcepub fn insert_tonic_extensions<T>(&self, request: &mut Request<T>)
pub fn insert_tonic_extensions<T>(&self, request: &mut Request<T>)
Inserts context values into request extensions for downstream layers.
Trait Implementations§
Source§impl Clone for RequestContext
impl Clone for RequestContext
Source§fn clone(&self) -> RequestContext
fn clone(&self) -> RequestContext
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RequestContext
impl Debug for RequestContext
Source§impl PartialEq for RequestContext
impl PartialEq for RequestContext
Source§fn eq(&self, other: &RequestContext) -> bool
fn eq(&self, other: &RequestContext) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for RequestContext
impl StructuralPartialEq for RequestContext
Auto Trait Implementations§
impl Freeze for RequestContext
impl RefUnwindSafe for RequestContext
impl Send for RequestContext
impl Sync for RequestContext
impl Unpin for RequestContext
impl UnsafeUnpin for RequestContext
impl UnwindSafe for RequestContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request