pub struct Request { /* private fields */ }
Expand description
Represents an HTTP request.
Stores all the properties of the client’s request.
Implementations
sourceimpl Request
impl Request
sourcepub fn uri(&self) -> &Uri
pub fn uri(&self) -> &Uri
Returns a reference to the associated URI.
Examples
let req = Request::default();
assert_eq!(*req.uri(), *"/");
sourcepub fn uri_mut(&mut self) -> &mut Uri
pub fn uri_mut(&mut self) -> &mut Uri
Returns a mutable reference to the associated URI.
Examples
let mut req: Request= Request::default();
*req.uri_mut() = "/hello".parse().unwrap();
assert_eq!(*req.uri(), *"/hello");
sourcepub fn method(&self) -> &Method
pub fn method(&self) -> &Method
Returns a reference to the associated HTTP method.
Examples
let req = Request::default();
assert_eq!(*req.method(), Method::GET);
sourcepub fn method_mut(&mut self) -> &mut Method
pub fn method_mut(&mut self) -> &mut Method
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);
sourcepub fn version_mut(&mut self) -> &mut Version
pub fn version_mut(&mut self) -> &mut Version
Returns a mutable reference to the associated version.
sourcepub fn remote_addr(&self) -> Option<&SocketAddr>
pub fn remote_addr(&self) -> Option<&SocketAddr>
Get request remote address.
sourcepub fn headers(&self) -> &HeaderMap<HeaderValue>
pub fn headers(&self) -> &HeaderMap<HeaderValue>
Returns a reference to the associated header field map.
Examples
let req = Request::default();
assert!(req.headers().is_empty());
sourcepub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
Returns a mutable reference to the associated header field map.
Examples
let mut req: Request = Request::default();
req.headers_mut().insert(HOST, HeaderValue::from_static("world"));
assert!(!req.headers().is_empty());
sourcepub fn get_header<T>(&self, key: &str) -> Option<T> where
T: FromStr,
pub fn get_header<T>(&self, key: &str) -> Option<T> where
T: FromStr,
Get header with supplied name and try to parse to a ‘T’, returns None if failed or not found.
sourcepub fn body(&self) -> Option<&Body>
pub fn body(&self) -> Option<&Body>
Returns a reference to the associated HTTP body.
Examples
let req = Request::default();
assert!(req.body().is_some());
sourcepub fn body_mut(&mut self) -> Option<&mut Body>
pub fn body_mut(&mut self) -> Option<&mut Body>
Returns a mutable reference to the associated HTTP body.
sourcepub fn take_body(&mut self) -> Option<Body>
pub fn take_body(&mut self) -> Option<Body>
Take body form the request, and set the body to None in the request.
sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Returns a reference to the associated extensions.
Examples
let req = Request::default();
assert!(req.extensions().get::<i32>().is_none());
sourcepub fn extensions_mut(&mut self) -> &mut Extensions
pub fn extensions_mut(&mut self) -> &mut Extensions
Returns a mutable reference to the associated extensions.
Examples
let mut req = Request::default();
req.extensions_mut().insert("hello");
assert_eq!(req.extensions().get(), Some(&"hello"));
sourcepub fn accept(&self) -> Vec<Mime, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn accept(&self) -> Vec<Mime, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Get accept.
sourcepub fn frist_accept(&self) -> Option<Mime>
pub fn frist_accept(&self) -> Option<Mime>
Get first accept.
sourcepub fn content_type(&self) -> Option<Mime>
pub fn content_type(&self) -> Option<Mime>
Get content type.
Get CookieJar
reference.
Get CookieJar
mutable reference.
Get Cookie
from cookies.
sourcepub fn params_mut(&mut self) -> &mut HashMap<String, String, RandomState>
pub fn params_mut(&mut self) -> &mut HashMap<String, String, RandomState>
Get params mutable reference.
sourcepub fn get_param<T>(&self, key: &str) -> Option<T> where
T: FromStr,
pub fn get_param<T>(&self, key: &str) -> Option<T> where
T: FromStr,
Get param value from params.
sourcepub fn queries(&self) -> &MultiMap<String, String, RandomState>
pub fn queries(&self) -> &MultiMap<String, String, RandomState>
Get queries reference.
sourcepub fn get_query<F>(&self, key: &str) -> Option<F> where
F: FromStr,
pub fn get_query<F>(&self, key: &str) -> Option<F> where
F: FromStr,
Get query value from queries.
sourcepub async fn get_form<F>(&'_ mut self, key: &'_ str) -> Option<F> where
F: FromStr,
pub async fn get_form<F>(&'_ mut self, key: &'_ str) -> Option<F> where
F: FromStr,
Get field data from form.
sourcepub async fn get_file(&'_ mut self, key: &'_ str) -> Option<&'_ FilePart>
pub async fn get_file(&'_ mut self, key: &'_ str) -> Option<&'_ FilePart>
Get FilePart
reference from request.
sourcepub async fn get_files(
&'_ mut self,
key: &'_ str
) -> Option<&'_ Vec<FilePart, Global>>
pub async fn get_files(
&'_ mut self,
key: &'_ str
) -> Option<&'_ Vec<FilePart, Global>>
Get FilePart
lsit reference from request.
sourcepub async fn get_form_or_query<F>(&'_ mut self, key: &'_ str) -> Option<F> where
F: FromStr,
pub async fn get_form_or_query<F>(&'_ mut self, key: &'_ str) -> Option<F> where
F: FromStr,
Get value from form first if not found then get from query.
sourcepub async fn get_query_or_form<F>(&'_ mut self, key: &'_ str) -> Option<F> where
F: FromStr,
pub async fn get_query_or_form<F>(&'_ mut self, key: &'_ str) -> Option<F> where
F: FromStr,
Get value from query first if not found then get from form.
sourcepub async fn payload(&'_ mut self) -> Result<&'_ Vec<u8, Global>, ParseError>
pub async fn payload(&'_ mut self) -> Result<&'_ Vec<u8, Global>, ParseError>
Get request payload.
sourcepub async fn form_data(&'_ mut self) -> Result<&'_ FormData, ParseError>
pub async fn form_data(&'_ mut self) -> Result<&'_ FormData, ParseError>
Get FormData
reference from request.
sourcepub async fn read_text(&'_ mut self) -> Result<&'_ str, ParseError>
pub async fn read_text(&'_ mut self) -> Result<&'_ str, ParseError>
Read body as text from request.
sourcepub async fn read_from_text<T>(&'_ mut self) -> Result<T, ParseError> where
T: FromStr,
pub async fn read_from_text<T>(&'_ mut self) -> Result<T, ParseError> where
T: FromStr,
Read body as type T
from request.
sourcepub async fn read_from_json<T>(&'_ mut self) -> Result<T, ParseError> where
T: DeserializeOwned,
pub async fn read_from_json<T>(&'_ mut self) -> Result<T, ParseError> where
T: DeserializeOwned,
Read body as type T
from request.
sourcepub async fn read_from_form<T>(&'_ mut self) -> Result<T, ParseError> where
T: DeserializeOwned,
pub async fn read_from_form<T>(&'_ mut self) -> Result<T, ParseError> where
T: DeserializeOwned,
Read body as type T
from request.
sourcepub async fn read<T>(&'_ mut self) -> Result<T, ParseError> where
T: DeserializeOwned,
pub async fn read<T>(&'_ mut self) -> Result<T, ParseError> where
T: DeserializeOwned,
Read body as type T
from request.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl !UnwindSafe for Request
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more