pub struct RequestContext { /* private fields */ }Expand description
Who is calling, and which conversation the call belongs to.
Built by the transport adapter that accepted the request and passed down
through TaskService to
AsyncMessageHandler. One value rather
than a widening parameter list: the session id, the principal and (later) the
tenant are all facts about this request, and a handler that wants one
usually wants the others.
Not to be confused with CallContext, which is
interceptor metadata about the call being dispatched (method name, side of
the wire) and says nothing about who made it.
§The principal
principal is None when the agent serves anonymous
callers — no authenticator is configured, so there is nobody to name. It is
what AsyncConversationStore compares
against a context’s recorded owner, which is why the transport has to carry
it rather than the handler guessing: a handler that cannot tell two callers
apart hands the second one the first one’s conversation.
Implementations§
Source§impl RequestContext
impl RequestContext
Sourcepub fn anonymous() -> Self
pub fn anonymous() -> Self
A call from nobody in particular: no session, no principal.
The right context for an internal caller that is not serving a request — a bridge invoking a handler directly, or a test.
Sourcepub fn with_session(self, session_id: impl Into<String>) -> Self
pub fn with_session(self, session_id: impl Into<String>) -> Self
Name the conversation this call belongs to.
An empty string is the same as no session at all, which is what a wire
message with an unset context_id decodes to.
Sourcepub fn with_principal(self, principal: impl Into<Option<AuthPrincipal>>) -> Self
pub fn with_principal(self, principal: impl Into<Option<AuthPrincipal>>) -> Self
Attach the principal the transport authenticated.
Sourcepub fn session_id(&self) -> Option<&str>
pub fn session_id(&self) -> Option<&str>
The context id the caller supplied.
Sourcepub fn principal(&self) -> Option<&AuthPrincipal>
pub fn principal(&self) -> Option<&AuthPrincipal>
The authenticated principal, with whatever claims the authenticator attached.
Trait Implementations§
Source§impl Clone for RequestContext
impl Clone for RequestContext
Source§fn clone(&self) -> RequestContext
fn clone(&self) -> RequestContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RequestContext
impl Debug for RequestContext
Source§impl Default for RequestContext
impl Default for RequestContext
Source§fn default() -> RequestContext
fn default() -> 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
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