Skip to main content

Module routing

Module routing 

Source
Expand description

Runtime construction and dispatch for the schema protocols a service declares.

Routers implement either MetadataProtocolRouter, which selects operations from the request URI, method and headers, or BodyProtocolRouter, which can also inspect the complete body. Body routers receive only operations with no streaming input or output.

Every service, including a single-protocol service, checks protocol claims. Routers are asked in the claim order resolved from ProtocolOrder constraints. The built-in priority order and its wire compatibility implications are documented on ProtocolRegistry::BUILTIN. The first definite claim owns the request: it either identifies the operation or proceeds to routing, whose errors are terminal and serialized by that protocol. A RouteClaim::DeferredClaim offers an operation while later protocols try to claim definitively. If none does, the first deferred claim owns the request. A RouteClaim::DeferredRejection also lets later protocols try. If no definite or deferred claim succeeds, the first deferred rejection supplies the response; otherwise the service returns its protocol-neutral rejection.

Each router can inspect the service’s protocol IDs through RouterBuildContext::service_protocols. When both restJson1 and restXml are enabled, eligible requests without Content-Type offer deferred claims. If no protocol claims definitively, protocol priority selects restJson1.

Enabling another protocol also changes identification of REST payload requests. A REST-only service accepts an untyped blob payload with an arbitrary or absent Content-Type. In a multi-protocol service, that payload claims REST through application/octet-stream (or its modeled @mediaType). A request such as POST /upload with Content-Type: video/mp4, or without a content type, can therefore receive the protocol-neutral 404 after another protocol is enabled. Payload requests do not offer the deferred claims used by eligible payload-less requests. Model the payload’s media type or send its expected content type.

Body routers first inspect the head with BodyProtocolRouter::claim. A BodyRouteClaim::ClaimedWithRoute dispatches without collecting the body. BodyRouteClaim::Claimed collects the body and calls BodyProtocolRouter::route_with_body; BodyRouteClaim::NeedsBodyToClaim collects it and calls BodyProtocolRouter::claim_with_body first. Collection obeys the service’s routing body limits. Collected bytes are reused by later routers if the claim is declined and replayed to the selected handler.

Before collecting for NeedsBodyToClaim, the service checks metadata routers for a recognized streaming input, if its schema declares any. A match skips that body claim without retrying it. Recognition is cached for the request. Claims already made from the head retain their priority, including a body router’s Claimed result.

If every protocol declines and none supplies a deferred rejection, the service returns its protocol-neutral response, including for a single-protocol service: 404 with the XML body <UnknownOperationException/> followed by a newline and no Content-Type header.

Re-exports§

pub use route_errors::RoutingError;
pub use route_errors::RoutingErrorKind;

Modules§

route_errors
The standard routing rejection shared by every schema-mode protocol router.

Structs§

CollectedBody
The complete request body collected by the routing service.
MultiProtocolRoutingFuture
Response future for schema routing.
MultiProtocolRoutingService
A service routing normalized requests to a shared handler collection through the protocols the service declares.
MultiProtocolRoutingServiceBuilder
Collects routing inputs, validating and constructing them only in Self::build.
OperationTarget
A router’s operation target: its canonical schema, cached metadata and handler position.
ProtocolOptions
Shared service configuration and protocol settings, independent of generated implementations.
RouterBuildContext
Everything a protocol sees when building its router: the service, the assigned targets, the shared service configuration, and the protocol’s own settings section. Self::service_protocols lets a protocol detect conflicting combinations or adapt its claim behavior using the existing service schema. Constructed by the routing service builder, so a protocol never sees another protocol’s settings.

Enums§

BodyRouteClaim
A body-routed protocol’s answer to whether a request is its own.
ProtocolResolutionError
Failure to resolve a service’s protocol registrations or claim ordering.
RouteClaim
A protocol’s answer to whether a request is its own.
RouterBuildError
Failure to bind handlers, resolve protocols, or construct service routing.
SharedProtocolRouter
Operation router built by a server protocol and owned by the shared routing state.

Traits§

BodyProtocolRouter
Routes operations using the request head and, when needed, the complete body.
MetadataProtocolRouter
Selects an operation from request metadata alone.