pub trait CallInterceptor:
Send
+ Sync
+ 'static {
// Required methods
fn before<'a>(
&'a self,
req: &'a mut ClientRequest,
) -> impl Future<Output = Result<(), ClientError>> + Send + 'a;
fn after<'a>(
&'a self,
resp: &'a ClientResponse,
) -> impl Future<Output = Result<(), ClientError>> + Send + 'a;
// Provided method
fn on_error<'a>(
&'a self,
req: &'a ClientRequest,
err: &'a ClientError,
) -> impl Future<Output = ()> + Send + 'a { ... }
}Expand description
Hooks called before every A2A request and after every response.
Implement this trait to add cross-cutting concerns such as authentication,
logging, or metrics. Register interceptors via
crate::ClientBuilder::with_interceptor.
§Object-safety note
This trait uses impl Future return types with explicit lifetimes, which
is not object-safe. Internally the SDK wraps implementations in a
boxed-future shim. Callers implement the ergonomic trait API.
Required Methods§
Sourcefn before<'a>(
&'a self,
req: &'a mut ClientRequest,
) -> impl Future<Output = Result<(), ClientError>> + Send + 'a
fn before<'a>( &'a self, req: &'a mut ClientRequest, ) -> impl Future<Output = Result<(), ClientError>> + Send + 'a
Called before the request is sent.
Mutate req to modify parameters or inject headers.
Sourcefn after<'a>(
&'a self,
resp: &'a ClientResponse,
) -> impl Future<Output = Result<(), ClientError>> + Send + 'a
fn after<'a>( &'a self, resp: &'a ClientResponse, ) -> impl Future<Output = Result<(), ClientError>> + Send + 'a
Called after a successful response is received.
Not called when the request fails; see on_error.
Provided Methods§
Sourcefn on_error<'a>(
&'a self,
req: &'a ClientRequest,
err: &'a ClientError,
) -> impl Future<Output = ()> + Send + 'a
fn on_error<'a>( &'a self, req: &'a ClientRequest, err: &'a ClientError, ) -> impl Future<Output = ()> + Send + 'a
Called when the transport returns an error for a request this chain’s
before hooks saw, in reverse registration order like after.
It observes; it cannot change the error the caller receives. By then
the params have moved to the transport, so req.params is null;
req.method and req.extra_headers are as before left them. It is
not called when a before hook itself fails, nor for errors that
arrive later inside an open stream.
Not overriding it (the default does nothing) means the
interceptor never learns that the agent rejected what it attached. For
an interceptor that attaches credentials that is a real cost:
BearerAuthInterceptor overrides it
so a token the agent answered with 401 is dropped from its
provider’s cache rather than sent again until it expires.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".