Skip to main content

Request

Struct Request 

Source
pub struct Request { /* private fields */ }
Expand description

HTTP request representation.

Contains all components of an HTTP request.

Implementations§

Source§

impl Request

Source

pub async fn http_from_stream( stream: &ArcRwLockStream, config: &RequestConfigData, ) -> Result<Request, RequestError>

Parses an HTTP request from a TCP stream.

Wraps the stream in a buffered reader and delegates to http_from_reader. If the timeout is DEFAULT_LOW_SECURITY_HTTP_READ_TIMEOUT_MS, no timeout is applied.

§Arguments
  • &ArcRwLock<TcpStream> - The TCP stream to read from.
  • &RequestConfigData - Configuration for security limits and buffer settings.
§Returns
  • Result<Request, RequestError> - The parsed request or an error.
Source

pub async fn ws_from_stream( &self, stream: &ArcRwLockStream, config: &RequestConfigData, ) -> Result<Request, RequestError>

Parses a WebSocket request from a TCP stream.

Wraps the stream in a buffered reader and delegates to ws_from_reader. If the timeout is DEFAULT_LOW_SECURITY_WS_READ_TIMEOUT_MS, no timeout is applied.

§Arguments
  • &ArcRwLock<TcpStream>: The TCP stream to read from.
  • &RequestConfigData: Configuration for security limits and buffer settings.
§Returns
  • Result<Request, RequestError>: The parsed WebSocket request or an error.
Source

pub fn try_get_query<K>(&self, key: K) -> Option<RequestQuerysValue>
where K: AsRef<str>,

Tries to get a query parameter value by key.

The key type must implement AsRef conversion.

§Arguments
  • AsRef<str> - The query parameter key (implements AsRef).
§Returns
  • Option<RequestQuerysValue> - The parameter value if exists.
Source

pub fn get_query<K>(&self, key: K) -> RequestQuerysValue
where K: AsRef<str>,

Gets a query parameter value by key.

The key type must implement AsRef conversion.

§Arguments
  • AsRef<str> - The query parameter key (implements AsRef).
§Returns
  • RequestQuerysValue - The parameter value if exists.
§Panics

This function will panic if the query parameter key is not found.

Source

pub fn try_get_header<K>(&self, key: K) -> Option<RequestHeadersValue>
where K: AsRef<str>,

Tries to retrieve the value of a request header by its key.

§Arguments
  • AsRef<str> - The header’s key (must implement AsRef).
§Returns
  • Option<RequestHeadersValue> - The optional header values.
Source

pub fn get_header<K>(&self, key: K) -> RequestHeadersValue
where K: AsRef<str>,

Retrieves the value of a request header by its key.

§Arguments
  • AsRef<str> - The header’s key (must implement AsRef).
§Returns
  • RequestHeadersValue - The optional header values.
§Panics

This function will panic if the header key is not found.

Source

pub fn try_get_header_front<K>(&self, key: K) -> Option<RequestHeadersValueItem>
where K: AsRef<str>,

Tries to retrieve the first value of a request header by its key.

§Arguments
  • AsRef<str> - The header’s key (must implement AsRef).
§Returns
  • Option<RequestHeadersValueItem> - The first header value if exists.
Source

pub fn get_header_front<K>(&self, key: K) -> RequestHeadersValueItem
where K: AsRef<str>,

Retrieves the first value of a request header by its key.

§Arguments
  • AsRef<str> - The header’s key (must implement AsRef).
§Returns
  • RequestHeadersValueItem - The first header value if exists.
§Panics

This function will panic if the header key is not found.

Source

pub fn try_get_header_back<K>(&self, key: K) -> Option<RequestHeadersValueItem>
where K: AsRef<str>,

Tries to retrieve the last value of a request header by its key.

§Arguments
  • AsRef<str> - The header’s key (must implement AsRef).
§Returns
  • Option<RequestHeadersValueItem> - The last header value if exists.
Source

pub fn get_header_back<K>(&self, key: K) -> RequestHeadersValueItem
where K: AsRef<str>,

Retrieves the last value of a request header by its key.

§Arguments
  • AsRef<str> - The header’s key (must implement AsRef).
§Returns
  • RequestHeadersValueItem - The last header value if exists.
§Panics

This function will panic if the header key is not found.

Source

pub fn try_get_header_size<K>(&self, key: K) -> Option<usize>
where K: AsRef<str>,

Tries to retrieve the number of values for a specific header.

§Arguments
  • AsRef<str> - The header’s key (must implement AsRef).
§Returns
  • Option<usize> - The count of values for the header if exists.
Source

pub fn get_header_size<K>(&self, key: K) -> usize
where K: AsRef<str>,

Retrieves the number of values for a specific header.

§Arguments
  • AsRef<str> - The header’s key (must implement AsRef).
§Returns
  • usize - The count of values for the header.
§Panics

This function will panic if the header key is not found.

Source

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.
Source

pub fn get_headers_size(&self) -> usize

Retrieves the number of unique headers.

§Returns
  • usize - The count of unique header keys.
Source

pub fn has_header<K>(&self, key: K) -> bool
where K: AsRef<str>,

Checks if a specific header exists.

§Arguments
  • AsRef<str> - The header key to check (must implement AsRef).
§Returns
  • bool - Whether the header exists.
Source

pub fn has_header_value<K, V>(&self, key: K, value: V) -> bool
where K: AsRef<str>, V: AsRef<str>,

Checks if a header contains a specific value.

§Arguments
  • AsRef<str> - The header key to check (must implement AsRef).
  • AsRef<str> - The value to search for (must implement AsRef).
§Returns
  • bool - Whether the header contains the value.
Source

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.
Source

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_ref 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.
Source

pub fn try_get_body_json<T>(&self) -> Result<T, Error>

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.

§Arguments
  • DeserializeOwned - The target type to deserialize as_ref (must implement DeserializeOwned).
§Returns
  • Result<T, serde_json::Error> - The deserialization result.
Source

pub fn get_body_json<T>(&self) -> T

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.

§Arguments
  • DeserializeOwned - The target type to deserialize as_ref (must implement DeserializeOwned).
§Returns
  • T - The deserialized body content.
§Panics

This function will panic if the deserialization fails.

Source

pub fn is_get_method(&self) -> bool

Checks whether the request method is GET.

§Returns
  • bool - Whether the method is GET.
Source

pub fn is_post_method(&self) -> bool

Checks whether the request method is POST.

§Returns
  • bool - Whether the method is POST.
Source

pub fn is_put_method(&self) -> bool

Checks whether the request method is PUT.

§Returns
  • bool - Whether the method is PUT.
Source

pub fn is_delete_method(&self) -> bool

Checks whether the request method is DELETE.

§Returns
  • bool - Whether the method is DELETE.
Source

pub fn is_patch_method(&self) -> bool

Checks whether the request method is PATCH.

§Returns
  • bool - Whether the method is PATCH.
Source

pub fn is_head_method(&self) -> bool

Checks whether the request method is HEAD.

§Returns
  • bool - Whether the method is HEAD.
Source

pub fn is_options_method(&self) -> bool

Checks whether the request method is OPTIONS.

§Returns
  • bool - Whether the method is OPTIONS.
Source

pub fn is_connect_method(&self) -> bool

Checks whether the request method is CONNECT.

§Returns
  • bool - Whether the method is CONNECT.
Source

pub fn is_trace_method(&self) -> bool

Checks whether the request method is TRACE.

§Returns
  • bool - Whether the method is TRACE.
Source

pub fn is_unknown_method(&self) -> bool

Checks whether the request method is UNKNOWN.

§Returns
  • bool - Whether the method is UNKNOWN.
Source

pub fn is_http0_9_version(&self) -> bool

Checks whether the HTTP version is HTTP/0.9.

§Returns
  • bool - Whether the version is HTTP/0.9.
Source

pub fn is_http1_0_version(&self) -> bool

Checks whether the HTTP version is HTTP/1.0.

§Returns
  • bool - Whether the version is HTTP/1.0.
Source

pub fn is_http1_1_version(&self) -> bool

Checks whether the HTTP version is HTTP/1.1.

§Returns
  • bool - Whether the version is HTTP/1.1.
Source

pub fn is_http1_1_or_higher_version(&self) -> bool

Checks if the HTTP version is HTTP/1.1 or higher.

§Returns
  • bool - Whether the version is HTTP/1.1 or higher.
Source

pub fn is_http2_version(&self) -> bool

Checks whether the HTTP version is HTTP/2.

§Returns
  • bool - Whether the version is HTTP/2.
Source

pub fn is_http3_version(&self) -> bool

Checks whether the HTTP version is HTTP/3.

§Returns
  • bool - Whether the version is HTTP/3.
Source

pub fn is_unknown_version(&self) -> bool

Checks whether the HTTP version is unknown.

§Returns
  • bool - Whether the version is unknown.
Source

pub fn is_http_version(&self) -> bool

Checks whether the version belongs to the HTTP family.

§Returns
  • bool - Whether the version is HTTP.
Source

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.
Source

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.
Source

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.
Source

pub fn is_unknown_upgrade_type(&self) -> bool

Checks whether the upgrade type is unknown.

§Returns
  • bool - Whether the upgrade type is unknown.
Source

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:

  1. If the Connection header exists:
    • Returns true if the header value is “keep-alive” (case-insensitive).
    • Returns false if the header value is “close” (case-insensitive).
  2. If no Connection header is present:
    • Returns true if the HTTP version is 1.1 or higher.
    • Returns false otherwise.
§Returns
  • bool - Whether keep-alive should be enabled.
Source

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

pub fn try_json_vec(&self) -> Result<Vec<u8>, Error>

Serializes the request to a JSON byte vector.

This method attempts to serialize the entire request structure into a JSON formatted byte vector representation.

§Returns
  • Result<Vec<u8>, serde_json::Error> - The serialized JSON bytes on success, or a serialization error on failure.
Source

pub fn json_vec(&self) -> Vec<u8>

Serializes the request to a JSON byte vector.

This method serializes the entire request structure into a JSON formatted byte vector representation.

§Returns
  • Vec<u8> - The serialized JSON bytes.
§Panics

This function will panic if the serialization fails.

Source

pub fn try_json_string(&self) -> Result<String, Error>

Serializes the request to a JSON string.

This method attempts to serialize the entire request structure into a JSON formatted string representation.

§Returns
  • Result<String, serde_json::Error> - The serialized JSON string on success, or a serialization error on failure.
Source

pub fn json_string(&self) -> String

Serializes the request to a JSON string.

This method serializes the entire request structure into a JSON formatted string representation.

§Returns
  • String - The serialized JSON string.
§Panics

This function will panic if the serialization fails.

Source§

impl Request

Source

pub fn get_method(&self) -> &RequestMethod

Source

pub fn get_host(&self) -> &RequestHost

Source

pub fn get_version(&self) -> &RequestVersion

Source

pub fn get_path(&self) -> &RequestPath

Source

pub fn get_querys(&self) -> &RequestQuerys

Source

pub fn get_headers(&self) -> &RequestHeaders

Source

pub fn get_body(&self) -> &RequestBody

Trait Implementations§

Source§

impl Clone for Request

Source§

fn clone(&self) -> Request

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Request

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Request

Provides a default value for Request.

Returns a new Request instance with all fields initialized to their default values.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Request

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Request

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Request

Source§

fn eq(&self, other: &Request) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Request

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Request

Source§

impl StructuralPartialEq for Request

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> AnySend for T
where T: Any + Send,

Source§

impl<T> AnySendClone for T
where T: Any + Send + Clone,

Source§

impl<T> AnySendSync for T
where T: Any + Send + Sync,

Source§

impl<T> AnySendSyncClone for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> AnySync for T
where T: Any + Sync,

Source§

impl<T> AnySyncClone for T
where T: Any + Sync + Clone,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,