pub struct Request {
pub method: Method,
pub path: String,
pub headers: HeaderMap,
pub params: FxHashMap<String, String>,
pub query: FxHashMap<String, String>,
/* private fields */
}Expand description
Incoming HTTP request with Express-style helpers.
Fields§
§method: Method§path: String§headers: HeaderMap§params: FxHashMap<String, String>§query: FxHashMap<String, String>Implementations§
Source§impl Request
impl Request
Sourcepub fn new(method: Method, path: impl Into<String>) -> Self
pub fn new(method: Method, path: impl Into<String>) -> Self
Build an empty request (tests / embedded). App::handle injects router state.
pub fn builder() -> RequestBuilder
Sourcepub fn body_limit(&self) -> usize
pub fn body_limit(&self) -> usize
Configured max body size (from the server / builder).
Sourcepub async fn body(&mut self) -> Result<Bytes>
pub async fn body(&mut self) -> Result<Bytes>
Collect the full body as bytes (respecting Self::body_limit).
Sourcepub async fn text(&mut self) -> Result<String>
pub async fn text(&mut self) -> Result<String>
Buffer the body if needed, then return UTF-8 text.
pub async fn json<T: DeserializeOwned>(&mut self) -> Result<T>
Sourcepub fn query_as<T: DeserializeOwned>(&self) -> Result<T>
pub fn query_as<T: DeserializeOwned>(&self) -> Result<T>
Deserialize the query string into T.
Sourcepub fn raw_query(&self) -> &str
pub fn raw_query(&self) -> &str
Raw query string without leading ? (for nested parsers like serde_qs).
pub fn query(&self, key: &str) -> Option<&str>
pub fn param(&self, key: &str) -> Option<&str>
Sourcepub fn param_as<T: FromStr>(&self, key: &str) -> Result<T>
pub fn param_as<T: FromStr>(&self, key: &str) -> Result<T>
Parse a path param (FromStr), or BadRequest.
pub fn header(&self, name: &str) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
pub fn scheme(&self) -> &str
pub fn host(&self) -> &str
pub fn is_secure(&self) -> bool
Sourcepub fn into_body_stream(&mut self) -> Result<HttpBody>
pub fn into_body_stream(&mut self) -> Result<HttpBody>
Take the body as a stream (once). Subsequent body reads fail.
Sourcepub fn into_body_stream_as(&mut self, by: &'static str) -> Result<HttpBody>
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.
Sourcepub fn state<T>(&self) -> Arc<T> ⓘ
pub fn state<T>(&self) -> Arc<T> ⓘ
Shared app state. Panics if the type was never registered via app.state.
Sourcepub fn state_or_default<T>(&self) -> Arc<T> ⓘ
pub fn state_or_default<T>(&self) -> Arc<T> ⓘ
Like Self::state, but returns T::default() when unset.
pub fn try_state<T>(&self) -> Option<Arc<T>>
Sourcepub fn states(&self) -> Arc<StateMap> ⓘ
pub fn states(&self) -> Arc<StateMap> ⓘ
Shared application StateMap (same bag as app.state(...)).
Sourcepub fn set<T: Send + Sync + 'static>(&mut self, value: T)
pub fn set<T: Send + Sync + 'static>(&mut self, value: T)
Store a per-request value (e.g. from auth middleware).
pub fn get<T: Send + Sync + 'static>(&self) -> Option<&T>
pub fn get_mut<T: Send + Sync + 'static>(&mut self) -> Option<&mut T>
pub fn take<T: Send + Sync + 'static>(&mut self) -> Option<T>
Sourcepub fn on_upgrade(&mut self) -> Option<Result<OnUpgrade, Response>>
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).
Sourcepub fn route_meta<T>(&self) -> Option<Arc<T>>where
T: RouteValue,
pub fn route_meta<T>(&self) -> Option<Arc<T>>where
T: RouteValue,
Typed metadata from the matched route (crate::Router::with / plugin helpers).
Sourcepub fn deadline_remaining(&self) -> Option<Duration>
pub fn deadline_remaining(&self) -> Option<Duration>
Remaining request budget from crate::limits::Deadline, if set.