pub struct JsonRpcDispatcher { /* private fields */ }Expand description
JSON-RPC 2.0 request dispatcher.
Routes incoming JSON-RPC requests to the underlying RequestHandler.
Optionally applies CORS headers to all responses.
Also serves the agent card at GET /.well-known/agent-card.json so that
JSON-RPC servers can participate in agent card discovery (spec §8.3).
Implementations§
Source§impl JsonRpcDispatcher
impl JsonRpcDispatcher
Sourcepub fn new(handler: Arc<RequestHandler>) -> Self
pub fn new(handler: Arc<RequestHandler>) -> Self
Creates a new dispatcher wrapping the given handler with default configuration.
Sourcepub fn with_config(handler: Arc<RequestHandler>, config: DispatchConfig) -> Self
pub fn with_config(handler: Arc<RequestHandler>, config: DispatchConfig) -> Self
Creates a new dispatcher with the given configuration.
Sourcepub fn with_cors(self, cors: CorsConfig) -> Self
pub fn with_cors(self, cors: CorsConfig) -> Self
Sets CORS configuration for this dispatcher.
When set, all responses will include CORS headers, and OPTIONS preflight
requests will be handled automatically.
Sourcepub async fn dispatch(
&self,
req: Request<Incoming>,
) -> Response<BoxBody<Bytes, Infallible>>
pub async fn dispatch( &self, req: Request<Incoming>, ) -> Response<BoxBody<Bytes, Infallible>>
Dispatches a JSON-RPC request and returns an HTTP response.
For SendStreamingMessage and SubscribeToTask, the response uses
SSE (text/event-stream). All other methods return JSON.
JSON-RPC errors are always returned as HTTP 200 with an error body.
For the two streaming methods that includes an error raised before
the stream starts: it is a plain application/json JSON-RPC error
response, not SSE. The official conformance kit (a2aproject/a2a-tck)
requires this shape — it treats any text/event-stream answer as a
successful stream (STREAM-SUB-003/004). a2a-go v2.5.0’s client reads
streaming answers only as SSE and so loses these errors; that is
a2a-go’s divergence, pinned by scripts/go_sdk_interop.sh.
Trait Implementations§
Source§impl Debug for JsonRpcDispatcher
impl Debug for JsonRpcDispatcher
Source§impl Dispatcher for JsonRpcDispatcher
impl Dispatcher for JsonRpcDispatcher
Source§fn dispatch(
&self,
req: Request<Incoming>,
) -> Pin<Box<dyn Future<Output = DispatchResponse> + Send + '_>>
fn dispatch( &self, req: Request<Incoming>, ) -> Pin<Box<dyn Future<Output = DispatchResponse> + Send + '_>>
Source§fn request_handler(&self) -> Option<&Arc<RequestHandler>>
fn request_handler(&self) -> Option<&Arc<RequestHandler>>
Auto Trait Implementations§
impl !Freeze for JsonRpcDispatcher
impl !RefUnwindSafe for JsonRpcDispatcher
impl !UnwindSafe for JsonRpcDispatcher
impl Send for JsonRpcDispatcher
impl Sync for JsonRpcDispatcher
impl Unpin for JsonRpcDispatcher
impl UnsafeUnpin for JsonRpcDispatcher
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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