Request

Struct Request 

Source
pub struct Request<S: State> { /* private fields */ }
Expand description

An incoming request

Implementations§

Source§

impl<S: State> Request<S>

Source

pub fn state(&self) -> &S

Get a reference to the App’s state

Source

pub fn context(&self) -> &S::Context

Get a reference to the request’s context

Source

pub fn context_mut(&mut self) -> &mut S::Context

Get a mut reference to the request’s context

Source

pub fn method(&self) -> &Method

Get the HTTP method being used by this request

Source

pub fn uri(&self) -> &Uri

Get the URI that was used for this request

Source

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

Parse the URI query string into an instance of T that derives Deserialize.

(To get the raw query string access it via req.uri().query()). If there is no query string, deserialize an empty string.

Source

pub fn header<T: Header>(&self) -> Option<T>

Get a typed header from the request (See also headers)

Source

pub fn headers(&self) -> &HeaderMap<HeaderValue>

Get all headers as a HeaderMap

Source

pub fn cookies(&self) -> Result<CookieJar>

Get the request’s cookies

Source

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

Get a route parameter (eg. :key or *key segments in the URI path)

If the parameter is not present, logs an error and returns a 400 Bad Request to the client

Source

pub fn params(&self) -> &Params

Get all route parameters

Source

pub async fn body_mut(&mut self) -> Result<&mut Body>

Get the request body as a hyper::Body

Source

pub async fn reader(&mut self) -> Result<impl Read + '_>

Get a reader to read the request body

(This does buffer the whole body into memory, but not necessarily contiguous memory). If you need to protect against malicious clients you should access the body via body_mut

Source

pub async fn body_bytes(&mut self) -> Result<Vec<u8>>

Get the request body as raw bytes in a Vec<u8>

Source

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

Get the request body as UTF-8 data in String

Source

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

Get the request body as JSON and deserialize into T.

If deserialization fails, log an error and return 400 Bad Request. (If this logic is not appropriate, consider using reader and using serde_json directly)

Source

pub fn remote_addr(&self) -> &SocketAddr

Get the address of the remote peer.

This method uses the network level address only and hence may be incorrect if you are behind a proxy. (This does not check for any Forwarded headers etc…)

Trait Implementations§

Source§

impl<S> HasSession for Request<S>
where S: State, S::Context: HasSession,

Implement HasSession on requests where the Context has sessions

Source§

fn session(&mut self) -> &mut Session

Get a reference to the Session for this current request

Auto Trait Implementations§

§

impl<S> !Freeze for Request<S>

§

impl<S> !RefUnwindSafe for Request<S>

§

impl<S> Send for Request<S>

§

impl<S> Sync for Request<S>

§

impl<S> Unpin for Request<S>
where <S as State>::Context: Unpin,

§

impl<S> !UnwindSafe for Request<S>

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> 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 = 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
Source§

impl<T> ErasedDestructor for T
where T: 'static,