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.2).
Implementations§
Source§impl JsonRpcDispatcher
impl JsonRpcDispatcher
Sourcepub fn new(handler: Arc<RequestHandler>) -> JsonRpcDispatcher
pub fn new(handler: Arc<RequestHandler>) -> JsonRpcDispatcher
Creates a new dispatcher wrapping the given handler with default configuration.
Sourcepub fn with_config(
handler: Arc<RequestHandler>,
config: DispatchConfig,
) -> JsonRpcDispatcher
pub fn with_config( handler: Arc<RequestHandler>, config: DispatchConfig, ) -> JsonRpcDispatcher
Creates a new dispatcher with the given configuration.
Sourcepub fn with_cors(self, cors: CorsConfig) -> JsonRpcDispatcher
pub fn with_cors(self, cors: CorsConfig) -> JsonRpcDispatcher
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, !>>
pub async fn dispatch( &self, req: Request<Incoming>, ) -> Response<BoxBody<Bytes, !>>
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 = Response<BoxBody<Bytes, !>>> + Send + '_>>
fn dispatch( &self, req: Request<Incoming>, ) -> Pin<Box<dyn Future<Output = Response<BoxBody<Bytes, !>>> + Send + '_>>
Source§fn request_handler(&self) -> Option<&Arc<RequestHandler>>
fn request_handler(&self) -> Option<&Arc<RequestHandler>>
Source§fn protocol_binding(&self) -> Option<&'static str>
fn protocol_binding(&self) -> Option<&'static str>
protocolBinding this dispatcher serves, as an agent card names
it ("JSONRPC", "HTTP+JSON"), if it serves exactly one. Read moreSource§fn close_upgraded(
&self,
_within: Duration,
) -> Pin<Box<dyn Future<Output = bool> + Send + '_>>
fn close_upgraded( &self, _within: Duration, ) -> Pin<Box<dyn Future<Output = bool> + Send + '_>>
WebSocket (ADR
0055), which the HTTP server no longer sees once hyper has handed
them over: each stops reading, lets its requests finish and sends a
Close frame. true when all of them ended within within.
Server::serve_with_shutdown calls it in its drain. The default
upgrades nothing.Auto Trait Implementations§
impl !Freeze for JsonRpcDispatcher
impl !RefUnwindSafe for JsonRpcDispatcher
impl !UnwindSafe for JsonRpcDispatcher
impl Forget for JsonRpcDispatcher
impl Move for JsonRpcDispatcher
impl Send for JsonRpcDispatcher
impl Sync for JsonRpcDispatcher
impl Unpin for JsonRpcDispatcher
impl UnsafeUnpin for JsonRpcDispatcher
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].