Skip to main content

Request

Struct Request 

Source
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: Method

The 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: Bytes

The raw request body. Empty for bodyless requests.

§headers: HeaderMap

The 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

Source

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.

Source

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.

Source

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.

Source

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 (or application/...+json) → parse JSON; body = Some(value), raw_body = original bytes. A parse error becomes WebError::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 becomes WebError::BadRequest.
  • any other content-type (application/octet-stream, application/zip, …) → body = None, raw_body = bytes. The handler reads params.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.)

Trait Implementations§

Source§

impl Clone for Request

Source§

fn clone(&self) -> Request

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Request

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more