Skip to main content

Request

Struct Request 

Source
pub struct Request {
    pub method: Method,
    pub path: String,
    pub headers: HeaderMap,
    pub params: HashMap<String, String>,
    pub query: HashMap<String, String>,
    /* private fields */
}
Expand description

Incoming HTTP request with Express-style helpers.

Fields§

§method: Method§path: String§headers: HeaderMap§params: HashMap<String, String>§query: HashMap<String, String>

Implementations§

Source§

impl Request

Source

pub async fn input(&mut self) -> Result<&FormData>

Parse form body once (urlencoded or multipart); cached on the request.

Source

pub async fn form<T: DeserializeOwned>(&mut self) -> Result<T>

Deserialize text fields into T (works for urlencoded and multipart text parts).

Source§

impl Request

Source

pub fn new(method: Method, path: impl Into<String>) -> Self

Build an empty request (tests / embedded). App::handle injects router state.

Source

pub fn builder() -> RequestBuilder

Source

pub fn body_limit(&self) -> usize

Configured max body size (from the server / builder).

Source

pub async fn body(&mut self) -> Result<Bytes>

Collect the full body as bytes (respecting Self::body_limit).

Source

pub async fn text(&mut self) -> Result<String>

Buffer the body if needed, then return UTF-8 text.

Source

pub async fn json<T: DeserializeOwned>(&mut self) -> Result<T>

Source

pub fn query_as<T: DeserializeOwned>(&self) -> Result<T>

Deserialize the query string into T.

Source

pub fn raw_query(&self) -> &str

Raw query string without leading ? (for nested parsers like serde_qs).

Source

pub fn query(&self, key: &str) -> Option<&str>

Source

pub fn param(&self, key: &str) -> Option<&str>

Source

pub fn param_as<T: FromStr>(&self, key: &str) -> Result<T>
where T::Err: Display,

Parse a path param (FromStr), or BadRequest.

Source

pub fn header(&self, name: &str) -> Option<&str>

Source

pub fn content_type(&self) -> Option<&str>

Source

pub fn scheme(&self) -> &str

Source

pub fn host(&self) -> &str

Source

pub fn is_secure(&self) -> bool

Source

pub fn url(&self) -> String

Absolute URL for this request path (no query).

Source

pub fn into_body_stream(&mut self) -> Result<HttpBody>

Take the body as a stream (once). Subsequent body reads fail.

Source

pub fn into_body_stream_as(&mut self, by: &'static str) -> Result<HttpBody>

Like Self::into_body_stream, recording by in later “already consumed” errors.

Source

pub fn state<T>(&self) -> Arc<T>
where T: Send + Sync + 'static,

Shared app state. Panics if the type was never registered via app.state.

Source

pub fn state_or_default<T>(&self) -> Arc<T>
where T: Default + Send + Sync + 'static,

Like Self::state, but returns T::default() when unset.

Source

pub fn try_state<T>(&self) -> Option<Arc<T>>
where T: Send + Sync + 'static,

Source

pub fn states(&self) -> Arc<StateMap>

Shared application StateMap (same bag as app.state(...)).

Source

pub fn set<T: Send + Sync + 'static>(&mut self, value: T)

Store a per-request value (e.g. from auth middleware).

Source

pub fn get<T: Send + Sync + 'static>(&self) -> Option<&T>

Source

pub fn get_mut<T: Send + Sync + 'static>(&mut self) -> Option<&mut T>

Source

pub fn take<T: Send + Sync + 'static>(&mut self) -> Option<T>

Source

pub fn on_upgrade(&mut self) -> Option<Result<OnUpgrade, Response>>

Take a pending HTTP/1 upgrade (WebSocket, …).

Returns 503 + Retry-After when crate::App::max_upgraded_connections is exhausted. Missing upgrade → None (not an error).

Source

pub fn route_meta<T>(&self) -> Option<Arc<T>>
where T: RouteValue,

Typed metadata from the matched route (crate::Router::with / plugin helpers).

Source

pub fn deadline_remaining(&self) -> Option<Duration>

Remaining request budget from crate::limits::Deadline, if set.

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> 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, 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<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