pub struct Request { /* private fields */ }Expand description
HTTP request representation.
Contains all components of an HTTP request.
The fields are crate-internal (§17.18): a consumer reaches them through
the generated get_* and set_* accessors.
Implementations§
Source§impl Request
Inherent implementation of Request.
impl Request
Inherent implementation of Request.
Sourcepub fn reset(&mut self) -> &mut Request
pub fn reset(&mut self) -> &mut Request
Resets the request to its default state while retaining allocated capacity.
This keeps the header map, query map, body, and string allocations so persistent (keep-alive) connections avoid repeated allocation per request.
§Returns
&mut Self- A mutable reference to self for chaining.
Sourcepub fn try_get_query<K>(&self, key: K) -> Option<VecDeque<String>>
pub fn try_get_query<K>(&self, key: K) -> Option<VecDeque<String>>
Tries to get a query parameter by key.
The key type must implement AsRef<str> conversion. A key that repeats in
the query carries every one of its values.
§Arguments
K- The query parameter key, which implementsAsRef<str>.
§Returns
Option<VecDeque<String>>- Every value of the parameter if it exists.
Sourcepub fn try_get_query_front<K>(&self, key: K) -> Option<String>
pub fn try_get_query_front<K>(&self, key: K) -> Option<String>
Sourcepub fn try_get_query_back<K>(&self, key: K) -> Option<String>
pub fn try_get_query_back<K>(&self, key: K) -> Option<String>
Sourcepub fn try_get_query_size<K>(&self, key: K) -> Option<usize>
pub fn try_get_query_size<K>(&self, key: K) -> Option<usize>
Sourcepub fn get_query_front<K>(&self, key: K) -> String
pub fn get_query_front<K>(&self, key: K) -> String
Sourcepub fn get_querys_size(&self) -> usize
pub fn get_querys_size(&self) -> usize
Retrieves the number of query parameters.
§Returns
usize- The count of distinct query parameter keys.
Sourcepub fn try_get_header<K>(&self, key: K) -> Option<VecDeque<String>>
pub fn try_get_header<K>(&self, key: K) -> Option<VecDeque<String>>
Tries to retrieve the value of a request header by its key.
The key is matched case-insensitively, because the parser stores every
header name lowercased and an HTTP header name is case-insensitive by
specification. Looking a header up with Content-Type and with
content-type therefore find the same value.
§Arguments
K- The header’s key, which must implementAsRef<str>.
§Returns
Option<VecDeque<String>>- The optional header values.
Sourcepub fn get_header<K>(&self, key: K) -> VecDeque<String>
pub fn get_header<K>(&self, key: K) -> VecDeque<String>
Sourcepub fn try_get_header_front<K>(&self, key: K) -> Option<String>
pub fn try_get_header_front<K>(&self, key: K) -> Option<String>
Sourcepub fn get_header_front<K>(&self, key: K) -> String
pub fn get_header_front<K>(&self, key: K) -> String
Sourcepub fn try_get_header_back<K>(&self, key: K) -> Option<String>
pub fn try_get_header_back<K>(&self, key: K) -> Option<String>
Sourcepub fn get_header_back<K>(&self, key: K) -> String
pub fn get_header_back<K>(&self, key: K) -> String
Sourcepub fn try_get_header_size<K>(&self, key: K) -> Option<usize>
pub fn try_get_header_size<K>(&self, key: K) -> Option<usize>
Sourcepub fn get_header_size<K>(&self, key: K) -> usize
pub fn get_header_size<K>(&self, key: K) -> usize
Sourcepub fn get_headers_values_size(&self) -> usize
pub fn get_headers_values_size(&self) -> usize
Retrieves the total number of header values across all headers.
§Returns
usize- The total count of all header values.
Sourcepub fn get_headers_size(&self) -> usize
pub fn get_headers_size(&self) -> usize
Sourcepub fn has_header<K>(&self, key: K) -> bool
pub fn has_header<K>(&self, key: K) -> bool
Sourcepub fn has_header_value<K, V>(&self, key: K, value: V) -> bool
pub fn has_header_value<K, V>(&self, key: K, value: V) -> bool
Sourcepub fn matches_if_none_match(&self, current_etag: &str) -> bool
pub fn matches_if_none_match(&self, current_etag: &str) -> bool
Checks If-None-Match against the entity-tag of an existing representation.
This explicitly invoked helper borrows normalized request headers and allocates nothing.
Strong and weak tags use case-sensitive weak comparison of their opaque values.
Repeated fields form one list; optional spaces, tabs, and empty list members are ignored.
A wildcard matches only when the entire field combination is a standalone *.
Missing headers, empty lists, invalid tags, or any malformed suffix return false,
even if an earlier tag matched. The current tag must be exactly one valid entity-tag,
without surrounding whitespace. Quoted commas and empty opaque values are valid;
backslashes are literal bytes, not escape characters.
Call only for a representation that already exists. This does not send a response,
automatically generate a 304, or implement complete HTTP precondition evaluation.
Callers decide whether to send 304 for GET/HEAD or 412 for other methods and must
handle precondition ordering themselves. Do not use this for If-Match, which
requires strong comparison.
§Arguments
&str- The current representation’s complete strong or weak entity-tag.
§Returns
bool- Whether a completely validIf-None-Matchmatches the existing representation.
Tries to parse cookies from the Cookie header.
This method retrieves the Cookie header value and parses it into
a collection of key-value pairs representing the cookies.
§Returns
Option<HashMapXxHash3_64<String, String>>- The parsed cookies if the header exists, otherwiseNone.
Gets a cookie value by its key.
This method first parses the cookies from the Cookie header,
then retrieves the value for the specified key.
§Arguments
K- The cookie key, which implementsAsRef<str>.
§Returns
String- The cookie value.
§Panics
This function will panic if the Cookie header is not found
or the cookie key does not exist.
Sourcepub fn get_upgrade_type(&self) -> UpgradeType
pub fn get_upgrade_type(&self) -> UpgradeType
Retrieves the upgrade type from the request headers.
This method looks for the UPGRADE header and attempts to parse its value
as_ref an UpgradeType. If the header is missing or the value is invalid,
it returns the default UpgradeType.
§Returns
UpgradeType- The parsed upgrade type.
Sourcepub fn get_body_string(&self) -> String
pub fn get_body_string(&self) -> String
Retrieves the body content of the request as a UTF-8 encoded string.
This method uses String::from_utf8_lossy to convert the byte slice returned by self.get_body() as a string.
If the byte slice contains invalid UTF-8 sequences, they will be replaced with the Unicode replacement character ().
§Returns
String- The body content as a string.
Sourcepub fn try_get_body_json<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
pub fn try_get_body_json<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
Deserializes the body content of the request as_ref a specified type T.
This method first retrieves the body content as a byte slice using self.get_body().
It then attempts to deserialize the byte slice as_ref the specified type T using json_from_slice.
The target type T is a type parameter of this method and must implement DeserializeOwned.
§Returns
Result<T, serde_json::Error>- The deserialization result.
Sourcepub fn get_body_json<T>(&self) -> Twhere
T: DeserializeOwned,
pub fn get_body_json<T>(&self) -> Twhere
T: DeserializeOwned,
Deserializes the body content of the request as_ref a specified type T.
This method first retrieves the body content as a byte slice using self.get_body().
It then attempts to deserialize the byte slice as_ref the specified type T using json_from_slice.
The target type T is a type parameter of this method and must implement DeserializeOwned.
§Returns
T- The deserialized body content.
§Panics
This function will panic if the deserialization fails.
Sourcepub fn is_ws_upgrade_type(&self) -> bool
pub fn is_ws_upgrade_type(&self) -> bool
Checks whether the WebSocket upgrade is enabled for this request.
This method determines if the UPGRADE header indicates a WebSocket connection.
§Returns
bool- Whether WebSocket upgrade is enabled.
Sourcepub fn is_multipart_form_data(&self) -> bool
pub fn is_multipart_form_data(&self) -> bool
Checks whether the request declares a multipart/form-data body.
§Returns
bool- Whether the request content type ismultipart/form-data.
Sourcepub fn try_get_content_type(&self) -> Option<String>
pub fn try_get_content_type(&self) -> Option<String>
Tries to get the request content type with its parameters stripped.
A Content-Type header such as text/html; charset=utf-8 yields the
media type alone, so a caller comparing against a media type does not
have to know that parameters may follow it.
§Returns
Option<String>- The media type, orNonewhen the header is absent.
Sourcepub fn try_get_content_type_parameter<K>(&self, name: K) -> Option<String>
pub fn try_get_content_type_parameter<K>(&self, name: K) -> Option<String>
Tries to get one parameter of the request Content-Type header.
The name is matched case-insensitively and a quoted value is unquoted,
so both boundary=abc and boundary="abc" yield abc.
§Arguments
K- The parameter name, which requires theAsRef<str>bound.
§Returns
Option<String>- The parameter value, orNonewhen absent.
Sourcepub fn try_get_body_form_data(&self) -> Option<Vec<BodyPart>>
pub fn try_get_body_form_data(&self) -> Option<Vec<BodyPart>>
Tries to decode a multipart/form-data body into its parts.
The boundary is read from the request Content-Type header rather than
guessed, so a body whose content type declares no boundary, a truncated
body, and a part without a name all yield None.
§Returns
Option<Vec<BodyPart>>- The decoded parts, orNonewhen unavailable.
Sourcepub fn get_body_form(
&self,
) -> HashMap<String, String, BuildHasherDefault<XxHash3_64>>
pub fn get_body_form( &self, ) -> HashMap<String, String, BuildHasherDefault<XxHash3_64>>
Decodes an application/x-www-form-urlencoded body into its fields.
§Returns
HashMapXxHash3_64<String, String>- The decoded form fields.
Sourcepub fn try_get_body_form_data_text<K>(&self, name: K) -> Option<String>
pub fn try_get_body_form_data_text<K>(&self, name: K) -> Option<String>
Sourcepub fn is_h2c_upgrade_type(&self) -> bool
pub fn is_h2c_upgrade_type(&self) -> bool
Checks if the current upgrade type is HTTP/2 cleartext (h2c).
§Returns
bool- Whether the upgrade type is h2c.
Sourcepub fn is_tls_upgrade_type(&self) -> bool
pub fn is_tls_upgrade_type(&self) -> bool
Checks if the current upgrade type is TLS (any version).
§Returns
bool- Whether the upgrade type is TLS.
Sourcepub fn is_unknown_upgrade_type(&self) -> bool
pub fn is_unknown_upgrade_type(&self) -> bool
Sourcepub fn is_enable_keep_alive(&self) -> bool
pub fn is_enable_keep_alive(&self) -> bool
Determines if a keep-alive connection should be enabled for this request.
This function checks the Connection header and the HTTP version to determine
if keep-alive should be enabled. The logic is as follows:
- If the
Connectionheader exists:- Returns
trueif the header value is “keep-alive” (case-insensitive). - Returns
falseif the header value is “close” (case-insensitive).
- Returns
- If no
Connectionheader is present:- Returns
trueif the HTTP version is 1.1 or higher. - Returns
falseotherwise.
- Returns
§Returns
bool- Whether keep-alive should be enabled.
Sourcepub fn is_disable_keep_alive(&self) -> bool
pub fn is_disable_keep_alive(&self) -> bool
Determines if keep-alive should be disabled for this request.
§Returns
bool- Whether keep-alive should be disabled.
Source§impl Request
impl Request
pub fn get_method(&self) -> &Method
pub fn get_mut_method(&mut self) -> &mut Method
pub fn set_method(&mut self, val: Method) -> &mut Request
pub fn get_host(&self) -> &String
pub fn get_mut_host(&mut self) -> &mut String
pub fn set_host(&mut self, val: String) -> &mut Request
pub fn get_version(&self) -> &HttpVersion
pub fn get_mut_version(&mut self) -> &mut HttpVersion
pub fn set_version(&mut self, val: HttpVersion) -> &mut Request
pub fn get_path(&self) -> &String
pub fn get_mut_path(&mut self) -> &mut String
pub fn set_path(&mut self, val: String) -> &mut Request
pub fn get_querys( &self, ) -> &HashMap<String, VecDeque<String>, BuildHasherDefault<XxHash3_64>>
pub fn get_mut_querys( &mut self, ) -> &mut HashMap<String, VecDeque<String>, BuildHasherDefault<XxHash3_64>>
pub fn set_querys( &mut self, val: HashMap<String, VecDeque<String>, BuildHasherDefault<XxHash3_64>>, ) -> &mut Request
pub fn get_headers( &self, ) -> &HashMap<String, VecDeque<String>, BuildHasherDefault<XxHash3_64>>
pub fn get_mut_headers( &mut self, ) -> &mut HashMap<String, VecDeque<String>, BuildHasherDefault<XxHash3_64>>
pub fn set_headers( &mut self, val: HashMap<String, VecDeque<String>, BuildHasherDefault<XxHash3_64>>, ) -> &mut Request
pub fn get_body(&self) -> &Vec<u8> ⓘ
pub fn get_mut_body(&mut self) -> &mut Vec<u8> ⓘ
pub fn set_body(&mut self, val: Vec<u8>) -> &mut Request
Trait Implementations§
Source§impl Default for Request
Provides a default value for Request.
impl Default for Request
Provides a default value for Request.
Returns a new Request instance with all fields initialized to their default values.
Source§impl<'de> Deserialize<'de> for Request
impl<'de> Deserialize<'de> for Request
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Request, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Request, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for Request
Source§impl Serialize for Request
impl Serialize for Request
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for Request
Auto Trait Implementations§
impl Forget for Request
impl Freeze for Requestwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<fn() -> XxHash3_64>: Freeze,
PhantomData<(String, VecDeque<String>)>: Freeze,
impl Move for Request
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnsafeUnpin for Requestwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<fn() -> XxHash3_64>: UnsafeUnpin,
PhantomData<(String, VecDeque<String>)>: UnsafeUnpin,
impl UnwindSafe for Requestwhere
RawVecInner: UnwindSafe,
HashMap<String, VecDeque<String>, BuildHasherDefault<XxHash3_64>>: UnwindSafe,
Blanket Implementations§
impl<T> AnySend for T
impl<T> AnySendClone for T
impl<T> AnySendSync for T
impl<T> AnySendSyncClone for T
impl<T> AnySync for T
impl<T> AnySyncClone for T
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.