pub struct Request {
pub method: Method,
pub path_parts: Vec<String>,
pub query_params: HashMap<String, Vec<String>>,
pub body: Bytes,
pub headers: HeaderMap,
pub rate_limit_class: Option<&'static str>,
}Expand description
An incoming HTTP request, as seen by middleware and used to build the
typed Params handed to a handler.
Fields§
§method: MethodThe HTTP method (GET, POST, …).
path_parts: Vec<String>The request path split on / into non-empty segments (no leading
empty segment); e.g. /api/users → ["api", "users"].
query_params: HashMap<String, Vec<String>>Query parameters as a multimap (each name → all its values, in order).
application/x-www-form-urlencoded body fields are appended into the
same map by Request::to_params.
body: BytesThe raw request body. Empty for bodyless requests.
headers: HeaderMapThe request headers.
rate_limit_class: Option<&'static str>The rate-limit class of the controller this request matched, as
declared by #[controller(rate_limit = "…")] (see
actus_controller::Controller::actus_rate_limit). None until the
server has matched a controller (it’s set right after routing, before
the middleware before chain runs) and for controllers that declared
no class.
This is the routing-derived projection a rate-limit crate::Middleware
reads to apply per-class policy — the framework supplies the label and
the 429 plumbing (WebError::TooManyRequests); the limiter and its
store stay application code. Unlike the wire-derived fields above, it’s
populated by the framework rather than parsed from the request.
Implementations§
Source§impl Request
impl Request
Sourcepub fn from_hyper_parts(req: Request<Incoming>) -> (Self, Incoming)
pub fn from_hyper_parts(req: Request<Incoming>) -> (Self, Incoming)
Build the Request skeleton from a hyper request without
consuming the body. The body stream is returned alongside; the
caller passes it back to Request::collect_body once it has
resolved the right body-size cap (which may depend on the matched
route — see Server::handle_request_inner).
This is the cheap half of Request::from_hyper: the per-request
allocations are just the path_parts Vec and query_params
HashMap; no IO happens. Use it when you need to inspect the
request shape before deciding how (or whether) to read the body.
Sourcepub async fn collect_body(
self,
body: Incoming,
max_body_bytes: usize,
inflight_budget: Option<&Arc<Semaphore>>,
) -> Result<Self, (Self, WebError)>
pub async fn collect_body( self, body: Incoming, max_body_bytes: usize, inflight_budget: Option<&Arc<Semaphore>>, ) -> Result<Self, (Self, WebError)>
Consume the body stream into this skeleton, capped at
max_body_bytes and (optionally) reserved against the
framework-wide inflight-bytes budget.
Returns Err((self, err)) on body failure (413, 400 truncated,
503 budget exhausted) — self is the same skeleton (with body
still empty) the caller passed in, so the error response still
has the request headers etc. and flows through the after-chain
like every other reply.
Sourcepub async fn from_hyper(
req: Request<Incoming>,
max_body_bytes: usize,
inflight_budget: Option<&Arc<Semaphore>>,
) -> Result<Self, (Self, WebError)>
pub async fn from_hyper( req: Request<Incoming>, max_body_bytes: usize, inflight_budget: Option<&Arc<Semaphore>>, ) -> Result<Self, (Self, WebError)>
Creates a new Request from a hyper::Request, buffering its body
(capped at max_body_bytes — see Server::with_max_body_bytes).
Convenience wrapper around Request::from_hyper_parts +
Request::collect_body: useful for tests and for callers that
don’t need to inspect the request shape before deciding the cap.
The server uses the two-step form directly so it can resolve the
cap from the matched controller (Phase 1) or route (Phase 2)
before reading the body.
Returns Err((skeleton, err)) when body collection fails (413
over the cap, 400 truncated, or 503 when the framework-level
with_max_inflight_body_bytes budget is exhausted). The returned
Request skeleton is populated with method / path / query /
headers — only body is empty — so the caller can route the
error through the normal reply pipeline.
Sourcepub fn to_params(&self) -> Result<Params, WebError>
pub fn to_params(&self) -> Result<Params, WebError>
Converts the request into a Params object for controller methods.
Body handling is content-type discriminated. Each non-empty body
must declare its type via Content-Type; the four outcomes are:
application/json(orapplication/...+json) → parse JSON;body = Some(value),raw_body = original bytes. A parse error becomesWebError::BadRequest.application/x-www-form-urlencoded→ parse into fields and append them to the query multimap (so a form field with the same name as a query parameter accumulates rather than clobbering);body = None,raw_body = bytes. A parse error becomesWebError::BadRequest.- any other content-type (
application/octet-stream,application/zip, …) →body = None,raw_body = bytes. The handler readsparams.body_bytes()directly. - empty body →
body = None,raw_body = Bytes::new(). The content-type header is ignored when there’s nothing to parse.
A non-empty body with no Content-Type header is rejected:
“discipline tightening” per design — the framework refuses to
guess, and the handler never sees a body whose shape it can’t
trust. (This is a behavior change from the previous
auto-JSON-sniff path; auto-sniff silently dropped binary
payloads on the floor.)