pub struct RestDispatcher { /* private fields */ }Expand description
REST HTTP request dispatcher.
Routes requests by HTTP method and path to the underlying RequestHandler.
Optionally applies CORS headers to all responses.
Implementations§
Source§impl RestDispatcher
impl RestDispatcher
Sourcepub fn new(handler: Arc<RequestHandler>) -> RestDispatcher
pub fn new(handler: Arc<RequestHandler>) -> RestDispatcher
Creates a new REST dispatcher with default configuration.
Sourcepub fn with_config(
handler: Arc<RequestHandler>,
config: DispatchConfig,
) -> RestDispatcher
pub fn with_config( handler: Arc<RequestHandler>, config: DispatchConfig, ) -> RestDispatcher
Creates a new REST dispatcher with the given configuration.
Sourcepub fn with_cors(self, cors: CorsConfig) -> RestDispatcher
pub fn with_cors(self, cors: CorsConfig) -> RestDispatcher
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 an HTTP request to the appropriate handler method.
The response’s media type is negotiated (§11.1):
application/a2a+json unless the request’s Accept prefers
application/json, or asks for an event stream with no JSON type and
no application/a2a+json body (media_type has the rule and why).
The agent card and the health probes are always application/json.
Trait Implementations§
Source§impl Debug for RestDispatcher
impl Debug for RestDispatcher
Source§impl Dispatcher for RestDispatcher
impl Dispatcher for RestDispatcher
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 RestDispatcher
impl !RefUnwindSafe for RestDispatcher
impl !UnwindSafe for RestDispatcher
impl Forget for RestDispatcher
impl Move for RestDispatcher
impl Send for RestDispatcher
impl Sync for RestDispatcher
impl Unpin for RestDispatcher
impl UnsafeUnpin for RestDispatcher
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].