pub struct Request { /* private fields */ }Expand description
Represents an HTTP request.
Stores all the properties of the client’s request.
Implementations§
Source§impl Request
 
impl Request
Sourcepub fn from_hyper<B>(req: Request<B>, scheme: Scheme) -> Request
 
pub fn from_hyper<B>(req: Request<B>, scheme: Scheme) -> Request
Creates a new Request from hyper::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.
Notice: If you using this mutable reference to change the uri, you should change the params and queries manually.
§Examples
let mut req: Request= Request::default();
*req.uri_mut() = "/hello".parse().unwrap();
assert_eq!(*req.uri(), *"/hello");Sourcepub fn set_uri(&mut self, uri: Uri)
 
pub fn set_uri(&mut self, uri: Uri)
Set the associated URI. queries will be reset.
Notice: params will not reset.
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 scheme_mut(&mut self) -> &mut Scheme
 
pub fn scheme_mut(&mut self) -> &mut Scheme
Returns a mutable reference to the associated scheme.
Sourcepub fn remote_addr(&self) -> &SocketAddr
 
pub fn remote_addr(&self) -> &SocketAddr
Get request remote address.
Sourcepub fn remote_addr_mut(&mut self) -> &mut SocketAddr
 
pub fn remote_addr_mut(&mut self) -> &mut SocketAddr
Get request remote address.
Sourcepub fn local_addr(&self) -> &SocketAddr
 
pub fn local_addr(&self) -> &SocketAddr
Get request local address reference.
Sourcepub fn local_addr_mut(&mut self) -> &mut SocketAddr
 
pub fn local_addr_mut(&mut self) -> &mut SocketAddr
Get mutable request local address reference.
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
 
pub fn headers_mut(&mut self) -> &mut HeaderMap
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 try_header<'de, T>(
    &'de self,
    key: impl AsHeaderName,
) -> Result<T, ParseError>where
    T: Deserialize<'de>,
 
pub fn try_header<'de, T>(
    &'de self,
    key: impl AsHeaderName,
) -> Result<T, ParseError>where
    T: Deserialize<'de>,
Try to get header with supplied name and try to parse to a ‘T’.
Sourcepub fn add_header<N, V>(
    &mut self,
    name: N,
    value: V,
    overwrite: bool,
) -> Result<&mut Request, Error>
 
pub fn add_header<N, V>( &mut self, name: N, value: V, overwrite: bool, ) -> Result<&mut Request, Error>
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_mut(&mut self) -> &mut ReqBody
 
pub fn body_mut(&mut self) -> &mut ReqBody
Returns a mutable reference to the associated HTTP body.
Sourcepub fn replace_body(&mut self, body: ReqBody) -> ReqBody
 
pub fn replace_body(&mut self, body: ReqBody) -> ReqBody
Sets body to a new value and returns old value.
Sourcepub fn take_body(&mut self) -> ReqBody
 
pub fn take_body(&mut self) -> ReqBody
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 set_secure_max_size(&mut self, size: usize)
 
pub fn set_secure_max_size(&mut self, size: usize)
Set secure max size, default value is 64KB.
Sourcepub fn secure_max_size(&self) -> usize
 
pub fn secure_max_size(&self) -> usize
Get secure max size, default value is 64KB.
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 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.
Get CookieJar reference.
Get CookieJar mutable reference.
Get Cookie from cookies.
Sourcepub fn params(&self) -> &PathParams
 
pub fn params(&self) -> &PathParams
Get params reference.
Sourcepub fn params_mut(&mut self) -> &mut PathParams
 
pub fn params_mut(&mut self) -> &mut PathParams
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 try_param<'de, T>(&'de self, key: &str) -> Result<T, ParseError>where
    T: Deserialize<'de>,
 
pub fn try_param<'de, T>(&'de self, key: &str) -> Result<T, ParseError>where
    T: Deserialize<'de>,
Try to get param value from params.
Sourcepub fn queries_mut(&mut self) -> &mut MultiMap<String, String>
 
pub fn queries_mut(&mut self) -> &mut MultiMap<String, String>
Get mutable queries reference.
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 fn try_query<'de, T>(&'de self, key: &str) -> Result<T, ParseError>where
    T: Deserialize<'de>,
 
pub fn try_query<'de, T>(&'de self, key: &str) -> Result<T, ParseError>where
    T: Deserialize<'de>,
Try to 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 try_form<'de, T>(&'de mut self, key: &str) -> Result<T, ParseError>where
    T: Deserialize<'de>,
 
pub async fn try_form<'de, T>(&'de mut self, key: &str) -> Result<T, ParseError>where
    T: Deserialize<'de>,
Try to 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 try_form_or_query<'de, T>(
    &'de mut self,
    key: &str,
) -> Result<T, ParseError>where
    T: Deserialize<'de>,
 
pub async fn try_form_or_query<'de, T>(
    &'de mut self,
    key: &str,
) -> Result<T, ParseError>where
    T: Deserialize<'de>,
Try to 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 try_query_or_form<'de, T>(
    &'de mut self,
    key: &str,
) -> Result<T, ParseError>where
    T: Deserialize<'de>,
 
pub async fn try_query_or_form<'de, T>(
    &'de mut self,
    key: &str,
) -> Result<T, ParseError>where
    T: Deserialize<'de>,
Try to get value from query, if key is not found in queries, then get from form.
Sourcepub async fn file(&mut self, key: &str) -> Option<&FilePart>
 
pub async fn file(&mut self, key: &str) -> Option<&FilePart>
Get FilePart reference from request.
Sourcepub async fn try_file(
    &mut self,
    key: &str,
) -> Result<Option<&FilePart>, ParseError>
 
pub async fn try_file( &mut self, key: &str, ) -> Result<Option<&FilePart>, ParseError>
Try to 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 try_first_file(&mut self) -> Result<Option<&FilePart>, ParseError>
 
pub async fn try_first_file(&mut self) -> Result<Option<&FilePart>, ParseError>
Try to get FilePart reference from request.
Sourcepub async fn files(&mut self, key: &str) -> Option<&Vec<FilePart>>
 
pub async fn files(&mut self, key: &str) -> Option<&Vec<FilePart>>
Get FilePart list reference from request.
Sourcepub async fn try_files(
    &mut self,
    key: &str,
) -> Result<Option<&Vec<FilePart>>, ParseError>
 
pub async fn try_files( &mut self, key: &str, ) -> Result<Option<&Vec<FilePart>>, ParseError>
Try to get FilePart list reference from request.
Sourcepub async fn try_all_files(&mut self) -> Result<Vec<&FilePart>, ParseError>
 
pub async fn try_all_files(&mut self) -> Result<Vec<&FilePart>, ParseError>
Try to get FilePart list reference from request.
Sourcepub async fn payload(&mut self) -> Result<&Bytes, ParseError>
 
pub async fn payload(&mut self) -> Result<&Bytes, ParseError>
Get request payload with default max size limit(64KB).
https://github.com/hyperium/hyper/issues/3111 *Notice: This method takes body.
Sourcepub async fn payload_with_max_size(
    &mut self,
    max_size: usize,
) -> Result<&Bytes, ParseError>
 
pub async fn payload_with_max_size( &mut self, max_size: usize, ) -> Result<&Bytes, ParseError>
Get request payload with max size limit.
https://github.com/hyperium/hyper/issues/3111 *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 and body’s size is not limited.
Sourcepub async fn extract<'de, T>(&'de mut self) -> Result<T, ParseError>
 
pub async fn extract<'de, T>(&'de mut self) -> Result<T, ParseError>
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> + Send,
 
pub async fn extract_with_metadata<'de, T>(
    &'de mut self,
    metadata: &'de Metadata,
) -> Result<T, ParseError>where
    T: Deserialize<'de> + Send,
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.
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 with default max size limit.
Sourcepub async fn parse_json_with_max_size<'de, T>(
    &'de mut self,
    max_size: usize,
) -> Result<T, ParseError>where
    T: Deserialize<'de>,
 
pub async fn parse_json_with_max_size<'de, T>(
    &'de mut self,
    max_size: usize,
) -> Result<T, ParseError>where
    T: Deserialize<'de>,
Parse json body as type T from request with max size limit.
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 with default max size.
Sourcepub async fn parse_body_with_max_size<'de, T>(
    &'de mut self,
    max_size: usize,
) -> Result<T, ParseError>where
    T: Deserialize<'de>,
 
pub async fn parse_body_with_max_size<'de, T>(
    &'de mut self,
    max_size: usize,
) -> Result<T, ParseError>where
    T: Deserialize<'de>,
Parse json body or form body as type T from request with max size.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Request
impl !RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl !UnwindSafe for Request
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
 
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
 
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
 
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> FutureExt for T
 
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
 
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
 
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> FutureTraceExt for Twhere
    T: FutureExt,
 
impl<T> FutureTraceExt for Twhere
    T: FutureExt,
Source§fn with_current_context_span(self, otel_span: Span) -> WithContext<Self> ⓘ
 
fn with_current_context_span(self, otel_span: Span) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
 
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
 
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
 
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
 
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
 
fn into_request(self) -> Request<T>
T in a tonic::Request