pub struct Request { /* private fields */ }Expand description
An HTTP request as seen by middleware, API routes and server actions.
Implementations§
Source§impl Request
impl Request
pub fn from_parts( parts: Parts, body: UnsyncBoxBody<Bytes, Box<dyn Error + Send + Sync>>, remote_addr: Option<SocketAddr>, body_limit: usize, secure_cookies: bool, ) -> Request
Sourcepub fn from_http(req: Request<Bytes>) -> Request
pub fn from_http(req: Request<Bytes>) -> Request
Build a request from any http::Request with a buffered body
(useful in tests and serverless adapters).
pub fn method(&self) -> &Method
pub fn uri(&self) -> &Uri
pub fn path(&self) -> &str
pub fn query_string(&self) -> &str
Sourcepub fn query<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
pub fn query<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
Deserialize the query string into T.
Sourcepub fn query_param(&self, name: &str) -> Option<String>
pub fn query_param(&self, name: &str) -> Option<String>
A single query parameter.
pub fn headers(&self) -> &HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
Header value as text (None if missing or not visible ASCII).
pub fn params(&self) -> &Params
pub fn param(&self, name: &str) -> Option<&str>
pub fn remote_addr(&self) -> Option<SocketAddr>
pub fn extensions(&self) -> &Extensions
pub fn extensions_mut(&mut self) -> &mut Extensions
Sourcepub fn extension<T>(&self) -> Option<&T>
pub fn extension<T>(&self) -> Option<&T>
Typed request-scoped value inserted by middleware (e.g. the current user).
pub fn insert_extension<T>(&mut self, value: T)
Sourcepub fn set_path(&mut self, path_and_query: &str) -> Result<(), Error>
pub fn set_path(&mut self, path_and_query: &str) -> Result<(), Error>
Rewrite the request path (middleware only; routing happens afterwards).
Sourcepub fn set_body_limit(&mut self, limit: usize)
pub fn set_body_limit(&mut self, limit: usize)
Override the maximum body size for this request.
pub fn is_websocket_upgrade(&self) -> bool
Sourcepub async fn bytes(&mut self) -> Result<Bytes, Error>
pub async fn bytes(&mut self) -> Result<Bytes, Error>
Read the whole body (enforcing the body limit: 413 when exceeded). Can be called repeatedly; the body is buffered on first read.
Sourcepub async fn raw_body(&mut self) -> Result<Bytes, Error>
pub async fn raw_body(&mut self) -> Result<Bytes, Error>
Raw body — use for webhook signature verification.
pub async fn text(&mut self) -> Result<String, Error>
pub async fn json<T>(&mut self) -> Result<T, Error>where
T: DeserializeOwned,
Sourcepub async fn form<T>(&mut self) -> Result<T, Error>where
T: DeserializeOwned,
pub async fn form<T>(&mut self) -> Result<T, Error>where
T: DeserializeOwned,
application/x-www-form-urlencoded body.
Sourcepub fn take_body(
&mut self,
) -> Option<UnsyncBoxBody<Bytes, Box<dyn Error + Send + Sync>>>
pub fn take_body( &mut self, ) -> Option<UnsyncBoxBody<Bytes, Box<dyn Error + Send + Sync>>>
Take the streaming body (for large uploads). Returns None if the
body was already consumed.