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
pub fn headers(&self) -> &HeaderMap
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 header<'de, T>(&'de self, key: impl AsHeaderName) -> Option<T>where
T: Deserialize<'de>,
pub fn header<'de, T>(&'de self, key: impl AsHeaderName) -> Option<T>where
T: Deserialize<'de>,
Get header with supplied name and try to parse to a ‘T’, returns None if failed or not found.
sourcepub fn add_header<N, V>(
&mut self,
name: N,
value: V,
overwrite: bool
) -> Result<()>where
N: IntoHeaderName,
V: TryInto<HeaderValue>,
pub fn add_header<N, V>(
&mut self,
name: N,
value: V,
overwrite: bool
) -> Result<()>where
N: IntoHeaderName,
V: TryInto<HeaderValue>,
Modify a header for this request.
When overwrite
is set to true
, If the header is already present, the value will be replaced.
When overwrite
is set to false
, The new header is always appended to the request, even if the header already exists.
sourcepub fn with_header<N, V>(
&mut self,
name: N,
value: V,
overwrite: bool
) -> Result<&mut Self>where
N: IntoHeaderName,
V: TryInto<HeaderValue>,
pub fn with_header<N, V>(
&mut self,
name: N,
value: V,
overwrite: bool
) -> Result<&mut Self>where
N: IntoHeaderName,
V: TryInto<HeaderValue>,
Modify a header for this request.
When overwrite
is set to true
, If the header is already present, the value will be replaced.
When overwrite
is set to false
, The new header is always appended to the request, even if the header already exists.
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>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn accept(&self) -> Vec<Mime>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
Get accept.
sourcepub fn first_accept(&self) -> Option<Mime>
pub fn first_accept(&self) -> Option<Mime>
Get first accept.
sourcepub fn content_type(&self) -> Option<Mime>
pub fn content_type(&self) -> Option<Mime>
Get content type.
Available on crate feature cookie
only.
cookie
only.Get CookieJar
reference.
Available on crate feature cookie
only.
cookie
only.Get CookieJar
mutable reference.
Available on crate feature cookie
only.
cookie
only.Get Cookie
from cookies.
sourcepub fn params_mut(&mut self) -> &mut HashMap<String, String>
pub fn params_mut(&mut self) -> &mut HashMap<String, String>
Get params mutable reference.
sourcepub fn param<'de, T>(&'de self, key: &str) -> Option<T>where
T: Deserialize<'de>,
pub fn param<'de, T>(&'de self, key: &str) -> Option<T>where
T: Deserialize<'de>,
Get param value from params.
sourcepub fn query<'de, T>(&'de self, key: &str) -> Option<T>where
T: Deserialize<'de>,
pub fn query<'de, T>(&'de self, key: &str) -> Option<T>where
T: Deserialize<'de>,
Get query value from queries.
sourcepub async fn form<'de, T>(&'de mut self, key: &str) -> Option<T>where
T: Deserialize<'de>,
pub async fn form<'de, T>(&'de mut self, key: &str) -> Option<T>where
T: Deserialize<'de>,
Get field data from form.
sourcepub async fn form_or_query<'de, T>(&'de mut self, key: &str) -> Option<T>where
T: Deserialize<'de>,
pub async fn form_or_query<'de, T>(&'de mut self, key: &str) -> Option<T>where
T: Deserialize<'de>,
Get field data from form, if key is not found in form data, then get from query.
sourcepub async fn query_or_form<'de, T>(&'de mut self, key: &str) -> Option<T>where
T: Deserialize<'de>,
pub async fn query_or_form<'de, T>(&'de mut self, key: &str) -> Option<T>where
T: Deserialize<'de>,
Get value from query, if key is not found in queries, then get from form.
sourcepub async fn file<'a>(&'a mut self, key: &'a str) -> Option<&'a FilePart>
pub async fn file<'a>(&'a mut self, key: &'a str) -> Option<&'a FilePart>
Get FilePart
reference from request.
sourcepub async fn first_file(&mut self) -> Option<&FilePart>
pub async fn first_file(&mut self) -> Option<&FilePart>
Get FilePart
reference from request.
sourcepub async fn files<'a>(&'a mut self, key: &'a str) -> Option<&'a Vec<FilePart>>
pub async fn files<'a>(&'a mut self, key: &'a str) -> Option<&'a Vec<FilePart>>
Get FilePart
list reference from request.
sourcepub async fn all_files(&mut self) -> Vec<&FilePart>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub async fn all_files(&mut self) -> Vec<&FilePart>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
Get FilePart
list reference from request.
sourcepub async fn payload(&mut self) -> Result<&Vec<u8>, ParseError>
pub async fn payload(&mut self) -> Result<&Vec<u8>, ParseError>
Get request payload.
*Notice: This method takes body.
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.
*Notice: This method takes body.
sourcepub async fn extract<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Extractible<'de>,
pub async fn extract<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Extractible<'de>,
Extract request as type T
from request’s different parts.
sourcepub async fn extract_with_metadata<'de, T>(
&'de mut self,
metadata: &'de Metadata
) -> Result<T, ParseError>where
T: Deserialize<'de>,
pub async fn extract_with_metadata<'de, T>(
&'de mut self,
metadata: &'de Metadata
) -> Result<T, ParseError>where
T: Deserialize<'de>,
Extract request as type T
from request’s different parts.
sourcepub fn parse_params<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Deserialize<'de>,
pub fn parse_params<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Deserialize<'de>,
Parse url params as type T
from request.
sourcepub fn parse_queries<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Deserialize<'de>,
pub fn parse_queries<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Deserialize<'de>,
Parse queries as type T
from request.
sourcepub fn parse_headers<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Deserialize<'de>,
pub fn parse_headers<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Deserialize<'de>,
Parse headers as type T
from request.
Available on crate feature cookie
only.
cookie
only.Parse cookies as type T
from request.
sourcepub async fn parse_json<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Deserialize<'de>,
pub async fn parse_json<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Deserialize<'de>,
Parse json body as type T
from request.
sourcepub async fn parse_form<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Deserialize<'de>,
pub async fn parse_form<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Deserialize<'de>,
Parse form body as type T
from request.
sourcepub async fn parse_body<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Deserialize<'de>,
pub async fn parse_body<'de, T>(&'de mut self) -> Result<T, ParseError>where
T: Deserialize<'de>,
Parse json body or form 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 Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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 Twhere
V: MultiLane<T>,
impl<V, T> VZip<V> for Twhere
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