pub struct CallContext { /* private fields */ }Expand description
Metadata about the current server-side method call.
Passed to ServerInterceptor::before
and ServerInterceptor::after.
Implementations§
Source§impl CallContext
impl CallContext
Sourcepub fn caller_identity(&self) -> Option<&str>
pub fn caller_identity(&self) -> Option<&str>
Returns the caller identity, once something has established one.
Sourcepub fn set_caller_identity(&self, identity: impl Into<String>) -> bool
pub fn set_caller_identity(&self, identity: impl Into<String>) -> bool
Records who the caller is, if nothing has yet.
Returns true when this call set the identity and false when one was
already present — in which case the existing identity stands and the
argument is dropped.
Takes &self deliberately: the caller is established by an
authentication interceptor, and
ServerInterceptor::before receives
a shared reference. Anything that needs &mut here is unreachable from
the place that has the answer.
§Example
use a2a_protocol_server::CallContext;
let ctx = CallContext::new("SendMessage");
assert!(ctx.set_caller_identity("user@example.com"));
assert_eq!(ctx.caller_identity(), Some("user@example.com"));
// A second interceptor does not get to overwrite it.
assert!(!ctx.set_caller_identity("someone-else"));
assert_eq!(ctx.caller_identity(), Some("user@example.com"));Sourcepub fn extensions(&self) -> &[String]
pub fn extensions(&self) -> &[String]
Returns the active extension URIs.
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
Returns the request/trace ID if set.
Sourcepub const fn http_headers(&self) -> &HashMap<String, String>
pub const fn http_headers(&self) -> &HashMap<String, String>
Returns the HTTP request headers (read-only).
Source§impl CallContext
impl CallContext
Sourcepub fn new(method: impl Into<String>) -> Self
pub fn new(method: impl Into<String>) -> Self
Creates a new CallContext for the given method.
Sourcepub fn with_caller_identity(self, identity: String) -> Self
pub fn with_caller_identity(self, identity: String) -> Self
Sets the caller identity at construction.
For a caller building a context directly. An interceptor holding
&CallContext wants set_caller_identity.
Sourcepub fn with_extensions(self, extensions: Vec<String>) -> Self
pub fn with_extensions(self, extensions: Vec<String>) -> Self
Sets the active extensions.
Sourcepub fn with_request_id(self, id: impl Into<String>) -> Self
pub fn with_request_id(self, id: impl Into<String>) -> Self
Sets the request/trace ID explicitly.
Sourcepub fn with_http_headers(self, headers: HashMap<String, String>) -> Self
pub fn with_http_headers(self, headers: HashMap<String, String>) -> Self
Sets the HTTP headers map (replacing any existing headers).
Automatically extracts x-request-id into request_id
if present.
Sourcepub fn with_http_header(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_http_header( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Adds a single HTTP header (key is lowercased for case-insensitive matching).
If the key is x-request-id, also populates request_id.
Trait Implementations§
Source§impl Clone for CallContext
impl Clone for CallContext
Source§fn clone(&self) -> CallContext
fn clone(&self) -> CallContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for CallContext
impl RefUnwindSafe for CallContext
impl Send for CallContext
impl Sync for CallContext
impl Unpin for CallContext
impl UnsafeUnpin for CallContext
impl UnwindSafe for CallContext
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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 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>
T in a tonic::Request