Skip to main content

Request

Struct Request 

Source
pub struct Request { /* private fields */ }
Expand description

An HTTP request as seen by middleware, API routes and server actions.

Implementations§

Source§

impl Request

Source

pub fn from_parts( parts: Parts, body: RequestBody, remote_addr: Option<SocketAddr>, body_limit: usize, secure_cookies: bool, ) -> Self

Source

pub fn from_http(req: Request<Bytes>) -> Self

Build a request from any http::Request with a buffered body (useful in tests and serverless adapters).

Source

pub fn get(uri: &str) -> Self

A body-less GET request for uri (tests, static rendering).

Source

pub fn method(&self) -> &Method

Source

pub fn uri(&self) -> &Uri

Source

pub fn path(&self) -> &str

Source

pub fn query_string(&self) -> &str

Source

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

Deserialize the query string into T.

Source

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

A single query parameter.

Source

pub fn headers(&self) -> &HeaderMap

Source

pub fn headers_mut(&mut self) -> &mut HeaderMap

Source

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

Header value as text (None if missing or not visible ASCII).

Source

pub fn params(&self) -> &Params

Source

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

Source

pub fn cookies(&self) -> &Cookies

Source

pub fn remote_addr(&self) -> Option<SocketAddr>

Source

pub fn extensions(&self) -> &Extensions

Source

pub fn extensions_mut(&mut self) -> &mut Extensions

Source

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

Typed request-scoped value inserted by middleware (e.g. the current user).

Source

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

Source

pub fn set_path(&mut self, path_and_query: &str) -> Result<()>

Rewrite the request path (middleware only; routing happens afterwards).

Source

pub fn set_body_limit(&mut self, limit: usize)

Override the maximum body size for this request.

Source

pub fn is_websocket_upgrade(&self) -> bool

Source

pub fn is_secure(&self) -> bool

Whether the connection (or the trusted proxy) used HTTPS.

Source

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

Read the whole body (enforcing the body limit: 413 when exceeded). Can be called repeatedly; the body is buffered on first read.

Source

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

Raw body — use for webhook signature verification.

Source

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

Source

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

Source

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

application/x-www-form-urlencoded body.

Source

pub fn take_body(&mut self) -> Option<RequestBody>

Take the streaming body (for large uploads). Returns None if the body was already consumed.

Source

pub fn parts(&self) -> &Parts

Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.