Struct saphir::request::Request[][src]

pub struct Request<T = Body<Bytes>> { /* fields omitted */ }

Struct that wraps a hyper request + some magic

Implementations

impl<T> Request<T>[src]

pub fn peer_addr(&self) -> Option<&SocketAddr>[src]

Return the Peer SocketAddr if one was available when receiving the request

pub fn peer_addr_mut(&mut self) -> Option<&mut SocketAddr>[src]

pub fn cookies(&self) -> &CookieJar[src]

Get the cookies sent by the browsers.

Before accessing cookies, you will need to parse them, it is done with the parse_cookies method

// Parse cookies
req.parse_cookies();
// then use cookies
let cookie = req.cookies().get("MyCookie");

pub fn cookies_mut(&mut self) -> &mut CookieJar[src]

Get the cookies sent by the browsers in a mutable way

Before accessing cookies, you will need to parse them, it is done with the parse_cookies method

// Parse cookies
req.parse_cookies();
// then use cookies
let mut_cookie = req.cookies_mut().get("MyCookie");

pub fn captures(&self) -> &HashMap<String, String>[src]

Access the captured variables from the request path. E.g. a path composed as /user/{user_id}/profile will store a capture named "user_id".

let user_id = req.captures().get("user_id");
// retrieve user by id

pub fn captures_mut(&mut self) -> &mut HashMap<String, String>[src]

Access the captured variables from the request path, in a mutable way.

pub fn map<F, U>(self, f: F) -> Request<U> where
    F: FnOnce(T) -> U, 
[src]

Convert a request of T in a request of U

// req is Request<Body>
let req: Request<String> = req.map(|_ignored_body| "New body".to_string());

pub async fn async_map<F, Fut, U>(self, f: F) -> Request<U> where
    F: FnOnce(T) -> Fut,
    Fut: Future<Output = U>, 
[src]

Convert a request of T in a request of U through a future

// req is Request<Body>
let req = req.async_map(|b| async {hyper::body::to_bytes(b).await});

pub fn into_body(self) -> T[src]

Return body, dropping the request

// req is Request<Body<Bytes>>
let body = req.into_body();

pub fn parse_cookies(&mut self)[src]

Parse cookies from the Cookie header

impl<T: FromBytes + Unpin + 'static> Request<Body<T>>[src]

pub async fn load_body(self) -> Result<Request<T::Out>, SaphirError>[src]

Convert a request of T in a request of U through a future

// req is Request<Body<Bytes>>
let req = req.load_body().await.unwrap();
// req is now Request<Bytes>

impl<T, E> Request<Result<T, E>>[src]

pub fn transpose(self) -> Result<Request<T>, E>[src]

Convert a request of Result<T, E> in a Result<Request, E>

// req is Request<Result<String, String>>
let res = req.transpose();
assert!(res.is_ok());

impl<T> Request<Option<T>>[src]

pub fn transpose(self) -> Option<Request<T>>[src]

Convert a request of Option in a Option<Request, E>

// req is Request<Option<String>>
let opt = req.transpose();
assert!(opt.is_some());

Methods from Deref<Target = RawRequest<T>>

pub fn method(&self) -> &Method[src]

Returns a reference to the associated HTTP method.

Examples

let request: Request<()> = Request::default();
assert_eq!(*request.method(), Method::GET);

pub fn method_mut(&mut self) -> &mut Method[src]

Returns a mutable reference to the associated HTTP method.

Examples

let mut request: Request<()> = Request::default();
*request.method_mut() = Method::PUT;
assert_eq!(*request.method(), Method::PUT);

pub fn uri(&self) -> &Uri[src]

Returns a reference to the associated URI.

Examples

let request: Request<()> = Request::default();
assert_eq!(*request.uri(), *"/");

pub fn uri_mut(&mut self) -> &mut Uri[src]

Returns a mutable reference to the associated URI.

Examples

let mut request: Request<()> = Request::default();
*request.uri_mut() = "/hello".parse().unwrap();
assert_eq!(*request.uri(), *"/hello");

pub fn version(&self) -> Version[src]

Returns the associated version.

Examples

let request: Request<()> = Request::default();
assert_eq!(request.version(), Version::HTTP_11);

pub fn version_mut(&mut self) -> &mut Version[src]

Returns a mutable reference to the associated version.

Examples

let mut request: Request<()> = Request::default();
*request.version_mut() = Version::HTTP_2;
assert_eq!(request.version(), Version::HTTP_2);

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

Returns a reference to the associated header field map.

Examples

let request: Request<()> = Request::default();
assert!(request.headers().is_empty());

pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>[src]

Returns a mutable reference to the associated header field map.

Examples

let mut request: Request<()> = Request::default();
request.headers_mut().insert(HOST, HeaderValue::from_static("world"));
assert!(!request.headers().is_empty());

pub fn extensions(&self) -> &Extensions[src]

Returns a reference to the associated extensions.

Examples

let request: Request<()> = Request::default();
assert!(request.extensions().get::<i32>().is_none());

pub fn extensions_mut(&mut self) -> &mut Extensions[src]

Returns a mutable reference to the associated extensions.

Examples

let mut request: Request<()> = Request::default();
request.extensions_mut().insert("hello");
assert_eq!(request.extensions().get(), Some(&"hello"));

pub fn body(&self) -> &T[src]

Returns a reference to the associated HTTP body.

Examples

let request: Request<String> = Request::default();
assert!(request.body().is_empty());

pub fn body_mut(&mut self) -> &mut T[src]

Returns a mutable reference to the associated HTTP body.

Examples

let mut request: Request<String> = Request::default();
request.body_mut().push_str("hello world");
assert!(!request.body().is_empty());

Trait Implementations

impl<T> Deref for Request<T>[src]

type Target = RawRequest<T>

The resulting type after dereferencing.

impl<T> DerefMut for Request<T>[src]

Auto Trait Implementations

impl<T = Body<Bytes>> !RefUnwindSafe for Request<T>

impl<T> Send for Request<T> where
    T: Send

impl<T> Sync for Request<T> where
    T: Sync

impl<T> Unpin for Request<T> where
    T: Unpin

impl<T = Body<Bytes>> !UnwindSafe for Request<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.