pub struct Router { /* private fields */ }Expand description
A runtime HTTP router.
Routes are dispatched through a per-method radix trie (matchit). The
trie matches on the request path; a per-route match_fn then validates
typed captures (e.g. that {} parses as u32). Patterns that conflict
in the trie fall back to a linear scan within the same method bucket,
so registration never silently drops a route.
Implementations§
Source§impl Router
impl Router
Sourcepub fn route(
self: &Arc<Self>,
req: Request<Incoming>,
) -> Pin<Box<dyn Future<Output = Response<BoxBody>> + Send>>
pub fn route( self: &Arc<Self>, req: Request<Incoming>, ) -> Pin<Box<dyn Future<Output = Response<BoxBody>> + Send>>
Route a request to the appropriate handler.
Must be called on Arc<Router> so the router outlives the returned future.
The body is collected into bytes before handler dispatch, enabling
both Hyper and Axum body types to be handled uniformly.
Sourcepub fn route_with_bytes(
self: &Arc<Self>,
parts: Parts,
body_bytes: Bytes,
) -> Pin<Box<dyn Future<Output = Response<BoxBody>> + Send>>
pub fn route_with_bytes( self: &Arc<Self>, parts: Parts, body_bytes: Bytes, ) -> Pin<Box<dyn Future<Output = Response<BoxBody>> + Send>>
Route a request whose body has already been collected into bytes::Bytes.
Used by adapters that have a different body type from hyper::body::Incoming
(e.g. the Axum interop layer), and by anything that has already buffered
a body for an unrelated reason. Bypasses the max_body_size check;
the caller is responsible for any size limiting.