Context

Struct Context 

Source
pub struct Context(/* private fields */);
Expand description

The main application context, providing thread-safe access to request and response data.

This is a wrapper around ContextInner that uses an Arc<RwLock<>> to allow for shared, mutable access across asynchronous tasks.

Implementations§

Source§

impl Context

Implementation of methods for Context structure.

Source

pub async fn http_from_stream( &self, request_config: RequestConfig, ) -> Result<Request, RequestError>

Reads an HTTP request from the underlying stream.

§Arguments
  • RequestConfig - The request config.
§Returns
  • Result<Request, RequestError> - The parsed request or error.
Source

pub async fn ws_from_stream( &self, request_config: RequestConfig, ) -> Result<Request, RequestError>

Reads a WebSocket frame from the underlying stream.

§Arguments
  • RequestConfig - The request config.
§Returns
  • Result<Request, RequestError> - The parsed frame or error.
Source

pub async fn get_aborted(&self) -> bool

Checks if the context has been marked as aborted.

§Returns
  • bool - True if the context is aborted, otherwise false.
Source

pub async fn set_aborted(&self, aborted: bool) -> &Self

Sets the aborted flag for the context.

§Arguments
  • bool - The aborted state to set.
§Returns
  • &Self - Reference to self for method chaining.
Source

pub async fn aborted(&self) -> &Self

Marks the context as aborted.

§Returns
  • &Self - Reference to the modified context.
Source

pub async fn cancel_aborted(&self) -> &Self

Cancels the aborted state of the context.

§Returns
  • &Self - Reference to the modified context.
Source

pub async fn get_closed(&self) -> bool

Checks if the connection is marked as closed.

§Returns
  • bool - True if the connection is closed, otherwise false.
Source

pub async fn set_closed(&self, closed: bool) -> &Self

Sets the closed flag for the connection.

§Arguments
  • bool - The new value for the closed flag.
§Returns
  • &Self - Reference to the modified context.
Source

pub async fn closed(&self) -> &Self

Marks the connection as closed.

§Returns
  • &Self - Reference to the modified context.
Source

pub async fn cancel_closed(&self) -> &Self

Cancels the closed state of the connection.

§Returns
  • &Self - Reference to the modified context.
Source

pub async fn is_terminated(&self) -> bool

Checks if the connection has been terminated (aborted or closed).

§Returns
  • bool - True if the connection is either aborted or closed, otherwise false.
Source

pub async fn is_keep_alive(&self, keep_alive: bool) -> bool

Checks if the connection should be kept alive.

This method evaluates whether the connection should remain open based on the closed state and the keep_alive parameter.

§Arguments
  • bool - Whether keep-alive is enabled for the request.
§Returns
  • bool - True if the connection should be kept alive, otherwise false.
Source

pub async fn try_get_stream(&self) -> Option<ArcRwLockStream>

Retrieves the underlying network stream, if available.

§Returns
  • Option<ArcRwLockStream> - The thread-safe, shareable network stream if it exists.
Source

pub async fn get_stream(&self) -> ArcRwLockStream

Retrieves the underlying network stream.

§Returns
  • ArcRwLockStream - The thread-safe, shareable network stream.
§Panics
  • If the network stream is not found.
Source

pub async fn try_get_socket_addr(&self) -> Option<SocketAddr>

Retrieves the remote socket address of the connection.

§Returns
  • Option<SocketAddr> - The socket address of the remote peer if available.
Source

pub async fn get_socket_addr(&self) -> SocketAddr

Retrieves the remote socket address.

§Returns
  • SocketAddr - The socket address of the remote peer.
§Panics
  • If the socket address is not found.
Source

pub async fn try_get_socket_addr_string(&self) -> Option<String>

Retrieves the remote socket address as a string.

§Returns
  • Option<String> - The string representation of the socket address if available.
Source

pub async fn get_socket_addr_string(&self) -> String

Retrieves the remote socket address as a string.

§Returns
  • String - The string representation of the socket address.
§Panics
  • If the socket address is not found.
Source

pub async fn try_get_socket_host(&self) -> Option<SocketHost>

Retrieves the IP address part of the remote socket address.

§Returns
  • Option<SocketHost> - The IP address of the remote peer.
Source

pub async fn get_socket_host(&self) -> SocketHost

Retrieves the IP address part of the remote socket address.

§Returns
  • SocketHost - The IP address of the remote peer.
§Panics
  • If the socket address is not found.
Source

pub async fn try_get_socket_port(&self) -> Option<SocketPort>

Retrieves the port number part of the remote socket address.

§Returns
  • Option<SocketPort> - The port number of the remote peer if available.
Source

pub async fn get_socket_port(&self) -> SocketPort

Retrieves the port number part of the remote socket address.

§Returns
  • SocketPort - The port number of the remote peer.
§Panics
  • If the socket address is not found.
Source

pub async fn get_request(&self) -> Request

Retrieves the current HTTP request.

§Returns
  • Request - A clone of the current request.
Source

pub async fn with_request<F, Fut, R>(&self, func: F) -> R
where F: Fn(Request) -> Fut, Fut: FutureSendStatic<R>,

Executes an asynchronous closure with the current request.

This method provides temporary access to the request data without needing to clone it.

§Arguments
  • F - A closure that takes the Request and returns a future.
§Returns
  • R - The result of the provided closure’s future.
Source

pub async fn get_request_string(&self) -> String

Retrieves the string representation of the current request.

§Returns
  • String - The full request as a string.
Source

pub async fn get_request_version(&self) -> RequestVersion

Retrieves the HTTP version of the request.

§Returns
  • RequestVersion - The HTTP version of the request.
Source

pub async fn get_request_method(&self) -> RequestMethod

Retrieves the HTTP method of the request.

§Returns
  • RequestMethod - The HTTP method of the request.
Source

pub async fn get_request_host(&self) -> RequestHost

Retrieves the host from the request headers.

§Returns
  • RequestHost - The host part of the request’s URI.
Source

pub async fn get_request_path(&self) -> RequestPath

Retrieves the path of the request.

§Returns
  • RequestPath - The path part of the request’s URI.
Source

pub async fn get_request_querys(&self) -> RequestQuerys

Retrieves the query parameters of the request.

§Returns
  • RequestQuerys - A map containing the query parameters.
Source

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

Attempts to retrieve a specific query parameter by its key.

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

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

Retrieves a specific query parameter by its key, panicking if not found.

§Arguments
  • AsRef<str> - The query parameter key.
§Returns
  • RequestQuerysValue - The query parameter value if exists.
§Panics
  • If the query parameter is not found.
Source

pub async fn get_request_body(&self) -> RequestBody

Retrieves the body of the request.

§Returns
  • RequestBody - A clone of the request’s body.
Source

pub async fn get_request_body_string(&self) -> String

Retrieves the request body as a string.

§Returns
  • String - The request body converted to a string.
Source

pub async fn try_get_request_body_json<J>(&self) -> Result<J, Error>

Deserializes the request body from JSON into a specified type.

§Returns
  • Result<J, serde_json::Error> - The deserialized type J or a JSON error.
Source

pub async fn get_request_body_json<J>(&self) -> J

Deserializes the request body from JSON into a specified type, panicking if not found.

§Returns
  • J - The deserialized type J.
§Panics
  • If deserialization fails.
Source

pub async fn get_request_headers(&self) -> RequestHeaders

Retrieves all request headers.

§Returns
  • RequestHeaders - A clone of the request’s header map.
Source

pub async fn get_request_headers_length(&self) -> usize

Retrieves the total number of request headers.

§Returns
  • usize - The total number of headers in the request.
Source

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

Attempts to retrieve a specific request header by its key.

§Arguments
  • AsRef<str> - The header key.
§Returns
  • Option<RequestHeadersValue> - The header values if exists.
Source

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

Retrieves a specific request header by its key, panicking if not found.

§Arguments
  • AsRef<str> - The key of the header to retrieve.
§Returns
  • RequestHeadersValue - The header values if exists.
§Panics
  • If the header is not found.
Source

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

Attempts to retrieve the first value of a specific request header.

§Arguments
  • AsRef<str> - The key of the header.
§Returns
  • Option<RequestHeadersValueItem> - The first value of the header if it exists.
Source

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

Retrieves the first value of a specific request header, panicking if not found.

§Arguments
  • AsRef<str> - The key of the header.
§Returns
  • RequestHeadersValueItem - The first value of the header if it exists.
§Panics
  • If the header is not found.
Source

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

Attempts to retrieve the last value of a specific request header.

§Arguments
  • AsRef<str> - The key of the header.
§Returns
  • Option<RequestHeadersValueItem> - The last value of the header if it exists.
Source

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

Retrieves the last value of a specific request header, panicking if not found.

§Arguments
  • AsRef<str> - The key of the header.
§Returns
  • RequestHeadersValueItem - The last value of the header if it exists.
§Panics
  • If the header is not found.
Source

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

Attempts to retrieve the number of values for a specific request header.

§Arguments
  • AsRef<str> - The key of the header.
§Returns
  • Option<usize> - The number of values for the specified header if it exists.
Source

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

Retrieves the number of values for a specific request header.

§Arguments
  • AsRef<str> - The key of the header.
§Returns
  • usize - The number of values for the specified header.
§Panics
  • If the header is not found.
Source

pub async fn get_request_headers_values_length(&self) -> usize

Retrieves the total number of values across all request headers.

§Returns
  • usize - The total count of all values in all headers.
Source

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

Checks if a specific request header exists.

§Arguments
  • AsRef<str> - The key of the header to check.
§Returns
  • bool - True if the header exists, otherwise false.
Source

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

Checks if a request header has a specific value.

§Arguments
  • AsRef<str> - The header key.
  • AsRef<str> - The value to check.
§Returns
  • bool - True if header contains the value.
Source

pub async fn get_request_cookies(&self) -> Cookies

Parses and retrieves all cookies from the request headers.

§Returns
  • Cookies - A map of cookies parsed from the request’s Cookie header.

Attempts to retrieve a specific cookie by its name from the request.

§Arguments
  • AsRef<str> - The cookie name.
§Returns
  • Option<CookieValue> - The cookie value if exists.

Retrieves a specific cookie by its name from the request, panicking if not found.

§Arguments
  • AsRef<str> - The cookie name.
§Returns
  • CookieValue - The cookie value if exists.
§Panics
  • If the cookie is not found.
Source

pub async fn get_request_upgrade_type(&self) -> UpgradeType

Retrieves the upgrade type of the request.

§Returns
  • UpgradeType - The upgrade type of the request.
Source

pub async fn get_request_is_ws(&self) -> bool

Checks if the request is a WebSocket upgrade request.

§Returns
  • bool - True if this is a WebSocket upgrade request.
Source

pub async fn get_request_is_h2c(&self) -> bool

Checks if the request is an HTTP/2 cleartext (h2c) upgrade.

§Returns
  • bool - True if this is an h2c upgrade request.
Source

pub async fn get_request_is_tls(&self) -> bool

Checks if the request is a TLS upgrade.

§Returns
  • bool - True if this is a TLS upgrade request.
Source

pub async fn get_request_is_unknown_upgrade(&self) -> bool

Checks if the request has an unknown upgrade type.

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

pub async fn get_request_is_http1_1_or_higher(&self) -> bool

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

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

pub async fn get_request_is_http0_9(&self) -> bool

Checks if the request HTTP version is HTTP/0.9.

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

pub async fn get_request_is_http1_0(&self) -> bool

Checks if the request HTTP version is HTTP/1.0.

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

pub async fn get_request_is_http1_1(&self) -> bool

Checks if the request HTTP version is HTTP/1.1.

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

pub async fn get_request_is_http2(&self) -> bool

Checks if the request HTTP version is HTTP/2.

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

pub async fn get_request_is_http3(&self) -> bool

Checks if the request HTTP version is HTTP/3.

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

pub async fn get_request_is_unknown_version(&self) -> bool

Checks if the request has an unknown HTTP version.

§Returns
  • bool - True if the version is unknown.
Source

pub async fn get_request_is_http(&self) -> bool

Checks if the request uses HTTP protocol.

§Returns
  • bool - True if the version belongs to HTTP family.
Source

pub async fn get_request_is_get(&self) -> bool

Checks if the request method is GET.

§Returns
  • bool - True if the method is GET.
Source

pub async fn get_request_is_post(&self) -> bool

Checks if the request method is POST.

§Returns
  • bool - True if the method is POST.
Source

pub async fn get_request_is_put(&self) -> bool

Checks if the request method is PUT.

§Returns
  • bool - True if the method is PUT.
Source

pub async fn get_request_is_delete(&self) -> bool

Checks if the request method is DELETE.

§Returns
  • bool - True if the method is DELETE.
Source

pub async fn get_request_is_patch(&self) -> bool

Checks if the request method is PATCH.

§Returns
  • bool - True if the method is PATCH.
Source

pub async fn get_request_is_head(&self) -> bool

Checks if the request method is HEAD.

§Returns
  • bool - True if the method is HEAD.
Source

pub async fn get_request_is_options(&self) -> bool

Checks if the request method is OPTIONS.

§Returns
  • bool - True if the method is OPTIONS.
Source

pub async fn get_request_is_connect(&self) -> bool

Checks if the request method is CONNECT.

§Returns
  • bool - True if the method is CONNECT.
Source

pub async fn get_request_is_trace(&self) -> bool

Checks if the request method is TRACE.

§Returns
  • bool - True if the method is TRACE.
Source

pub async fn get_request_is_unknown_method(&self) -> bool

Checks if the request method is unknown.

§Returns
  • bool - True if the method is unknown.
Source

pub async fn get_request_is_enable_keep_alive(&self) -> bool

Checks if the connection should be kept alive based on request headers.

§Returns
  • bool - True if the Connection header suggests keeping the connection alive, otherwise false.
Source

pub async fn get_request_is_disable_keep_alive(&self) -> bool

Checks if keep-alive should be disabled for the request.

§Returns
  • bool - True if keep-alive should be disabled.
Source

pub async fn get_response(&self) -> Response

Retrieves the current HTTP response.

§Returns
  • Response - A clone of the current response.
Source

pub async fn set_response<T>(&self, response: T) -> &Self
where T: Borrow<Response>,

Sets the HTTP response for the context.

§Arguments
  • Borrow<Response> - The response to set in the context.
§Returns
  • &Self - Reference to the modified context.
Source

pub async fn with_response<F, Fut, R>(&self, func: F) -> R
where F: Fn(Response) -> Fut, Fut: FutureSendStatic<R>,

Executes an asynchronous closure with the current response.

§Arguments
  • F - A closure that takes the Response and returns a future.
§Returns
  • R - The result of the provided closure’s future.
Source

pub async fn get_response_string(&self) -> String

Retrieves the string representation of the current response.

§Returns
  • String - The full response as a string.
Source

pub async fn get_response_version(&self) -> ResponseVersion

Retrieves the HTTP version of the response.

§Returns
  • ResponseVersion - The HTTP version of the response.
Source

pub async fn set_response_version(&self, version: ResponseVersion) -> &Self

Sets the HTTP version for the response.

§Arguments
  • ResponseVersion - The HTTP version to set for the response.
§Returns
  • &Self - Reference to the modified context.
Source

pub async fn get_response_headers(&self) -> ResponseHeaders

Retrieves all response headers.

§Returns
  • ResponseHeaders - A clone of the response’s header map.
Source

pub async fn try_get_response_header<K>( &self, key: K, ) -> Option<ResponseHeadersValue>
where K: AsRef<str>,

Attempts to retrieve a specific response header by its key.

§Arguments
  • AsRef<str> - The key of the header to retrieve.
§Returns
  • Option<ResponseHeadersValue> - The header values if the header exists.
Source

pub async fn get_response_header<K>(&self, key: K) -> ResponseHeadersValue
where K: AsRef<str>,

Retrieves a specific response header by its key, panicking if not found.

§Arguments
  • AsRef<str> - The key of the header to retrieve.
§Returns
  • ResponseHeadersValue - The header values if the header exists.
§Panics
  • If the header is not found.
Source

pub async fn set_response_header<K, V>(&self, key: K, value: V) -> &Self
where K: AsRef<str>, V: AsRef<str>,

Sets a response header with a new value, removing any existing values.

§Arguments
  • K - The key of the header to set.
  • V - The new value for the header.
§Returns
  • &Self - Reference to the modified context.
Source

pub async fn try_get_response_header_front<K>( &self, key: K, ) -> Option<ResponseHeadersValueItem>
where K: AsRef<str>,

Attempts to retrieve the first value of a specific response header.

§Arguments
  • AsRef<str> - The key of the header.
§Returns
  • Option<ResponseHeadersValueItem> - The first value of the header if it exists.
Source

pub async fn get_response_header_front<K>( &self, key: K, ) -> ResponseHeadersValueItem
where K: AsRef<str>,

Retrieves the first value of a specific response header, panicking if not found.

§Arguments
  • AsRef<str> - The key of the header.
§Returns
  • ResponseHeadersValueItem - The first value of the header if it exists.
§Panics
  • If the header is not found.
Source

pub async fn try_get_response_header_back<K>( &self, key: K, ) -> Option<ResponseHeadersValueItem>
where K: AsRef<str>,

Attempts to retrieve the last value of a specific response header.

§Arguments
  • AsRef<str> - The key of the header.
§Returns
  • Option<ResponseHeadersValueItem> - The last value of the header if it exists.
Source

pub async fn get_response_header_back<K>( &self, key: K, ) -> ResponseHeadersValueItem
where K: AsRef<str>,

Retrieves the last value of a specific response header, panicking if not found.

§Arguments
  • AsRef<str> - The key of the header.
§Returns
  • ResponseHeadersValueItem - The last value of the header if it exists.
§Panics
  • If the header is not found.
Source

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

Checks if a specific response header exists.

§Arguments
  • AsRef<str> - The key of the header to check.
§Returns
  • bool - True if the header exists, otherwise false.
Source

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

Checks if a response header has a specific value.

§Arguments
  • AsRef<str> - The key of the header.
  • AsRef<str> - The value to check for.
§Returns
  • bool - True if the header contains the specified value, otherwise false.
Source

pub async fn get_response_headers_length(&self) -> usize

Retrieves the total number of response headers.

§Returns
  • usize - The total number of headers in the response.
Source

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

Attempts to retrieve the number of values for a specific response header.

§Arguments
  • AsRef<str> - The key of the header.
§Returns
  • Option<usize> - The number of values for the specified header if it exists.
Source

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

Retrieves the number of values for a specific response header.

§Arguments
  • AsRef<str> - The key of the header.
§Returns
  • usize - The number of values for the specified header.
§Panics
  • If the header is not found.
Source

pub async fn get_response_headers_values_length(&self) -> usize

Retrieves the total number of values across all response headers.

§Returns
  • usize - The total count of all values in all headers.
Source

pub async fn add_response_header<K, V>(&self, key: K, value: V) -> &Self
where K: AsRef<str>, V: AsRef<str>,

Adds a response header, adding it if it doesn’t exist or appending to it if it does.

§Arguments
  • AsRef<str> - The header key.
  • AsRef<str> - The header value.
§Returns
  • &Self - Reference to self for method chaining.
Source

pub async fn remove_response_header<K>(&self, key: K) -> &Self
where K: AsRef<str>,

Removes a response header and all its values.

§Arguments
  • AsRef<str> - The key of the header to remove.
§Returns
  • &Self - Reference to the modified context.
Source

pub async fn remove_response_header_value<K, V>( &self, key: K, value: V, ) -> &Self
where K: AsRef<str>, V: AsRef<str>,

Removes a specific value from a response header.

§Arguments
  • AsRef<str> - The header key.
  • AsRef<str> - The value to remove.
§Returns
  • &Self - Reference to self for method chaining.
Source

pub async fn clear_response_headers(&self) -> &Self

Clears all headers from the response.

§Returns
  • &Self - Reference to the modified context.
Source

pub async fn get_response_cookies(&self) -> Cookies

Parses and retrieves all cookies from the response headers.

§Returns
  • Cookies - A map of cookies parsed from the response’s Cookie header.

Attempts to retrieve a specific cookie by its name from the response.

§Arguments
  • AsRef<str> - The name of the cookie to retrieve.
§Returns
  • Option<CookieValue> - The cookie’s value if it exists.

Retrieves a specific cookie by its name from the response, panicking if not found.

§Arguments
  • AsRef<str> - The name of the cookie to retrieve.
§Returns
  • CookieValue - The cookie’s value if it exists.
§Panics
  • If the cookie is not found.
Source

pub async fn get_response_body(&self) -> ResponseBody

Retrieves the body of the response.

§Returns
  • ResponseBody - The response body.
Source

pub async fn set_response_body<B>(&self, body: B) -> &Self
where B: AsRef<[u8]>,

Sets the body of the response.

§Arguments
  • B - The body data to set for the response.
§Returns
  • &Self - Reference to the modified context.
Source

pub async fn get_response_body_string(&self) -> String

Retrieves the response body as a string.

§Returns
  • String - The response body converted to a string.
Source

pub async fn try_get_response_body_json<J>(&self) -> Result<J, Error>

Deserializes the response body from JSON into a specified type.

§Returns
  • Result<J, serde_json::Error> - The deserialized type J or a JSON error.
Source

pub async fn get_response_body_json<J>(&self) -> J

Deserializes the response body from JSON into a specified type, panicking if not found.

§Returns
  • J - The deserialized type J.
§Panics
  • If deserialization fails.
Source

pub async fn get_response_reason_phrase(&self) -> ResponseReasonPhrase

Retrieves the reason phrase of the response status code.

§Returns
  • ResponseReasonPhrase - The reason phrase associated with the response status code.
Source

pub async fn set_response_reason_phrase<P>(&self, reason_phrase: P) -> &Self
where P: AsRef<str>,

Sets the reason phrase for the response status code.

§Arguments
  • AsRef<str> - The reason phrase to set.
§Returns
  • &Self - Reference to the modified context.
Source

pub async fn get_response_status_code(&self) -> ResponseStatusCode

Retrieves the status code of the response.

§Returns
  • ResponseStatusCode - The status code of the response.
Source

pub async fn set_response_status_code( &self, status_code: ResponseStatusCode, ) -> &Self

Sets the status code for the response.

§Arguments
  • ResponseStatusCode - The status code to set for the response.
§Returns
  • &Self - A reference to the modified context.
Source

pub async fn get_route_params(&self) -> RouteParams

Retrieves the parameters extracted from the route path.

§Returns
  • RouteParams - A map containing the route parameters.
Source

pub async fn try_get_route_param<T>(&self, name: T) -> Option<String>
where T: AsRef<str>,

Attempts to retrieve a specific route parameter by its name.

§Arguments
  • AsRef<str> - The name of the route parameter to retrieve.
§Returns
  • Option<String> - The value of the route parameter if it exists.
Source

pub async fn get_route_param<T>(&self, name: T) -> String
where T: AsRef<str>,

Retrieves a specific route parameter by its name, panicking if not found.

§Arguments
  • AsRef<str> - The name of the route parameter to retrieve.
§Returns
  • String - The value of the route parameter if it exists.
§Panics
  • If the route parameter is not found.
Source

pub async fn get_attributes(&self) -> ThreadSafeAttributeStore

Retrieves all attributes stored in the context.

§Returns
  • ThreadSafeAttributeStore - A map containing all attributes.
Source

pub async fn try_get_attribute<K, V>(&self, key: K) -> Option<V>
where K: AsRef<str>, V: AnySendSyncClone,

Attempts to retrieve a specific attribute by its key, casting it to the specified type.

§Arguments
  • AsRef<str> - The key of the attribute to retrieve.
§Returns
  • Option<V> - The attribute value if it exists and can be cast to the specified type.
Source

pub async fn get_attribute<K, V>(&self, key: K) -> V
where K: AsRef<str>, V: AnySendSyncClone,

Retrieves a specific attribute by its key, casting it to the specified type, panicking if not found.

§Arguments
  • AsRef<str> - The key of the attribute to retrieve.
§Returns
  • V - The attribute value if it exists and can be cast to the specified type.
§Panics
  • If the attribute is not found.
Source

pub async fn set_attribute<K, V>(&self, key: K, value: V) -> &Self
where K: AsRef<str>, V: AnySendSyncClone,

Sets an attribute in the context.

§Arguments
  • AsRef<str> - The key of the attribute to set.
  • AnySendSyncClone - The value of the attribute.
§Returns
  • &Self - A reference to the modified context.
Source

pub async fn remove_attribute<K>(&self, key: K) -> &Self
where K: AsRef<str>,

Removes an attribute from the context.

§Arguments
  • AsRef<str> - The key of the attribute to remove.
§Returns
  • &Self - A reference to the modified context.
Source

pub async fn clear_attribute(&self) -> &Self

Clears all attributes from the context.

§Returns
  • &Self - A reference to the modified context.
Source

pub async fn try_get_panic(&self) -> Option<Panic>

Retrieves panic information if a panic has occurred during handling.

§Returns
  • Option<Panic> - The panic information if a panic was caught.
Source

pub async fn get_panic(&self) -> Panic

Retrieves panic information if a panic has occurred during handling.

§Returns
  • Panic - The panic information if a panic was caught.
§Panics
  • If the panic information is not found.
Source

pub async fn set_hook<K, F, Fut>(&self, key: K, hook: F) -> &Self

Sets a hook function for the context with a custom key.

§Arguments
  • ToString - The key to identify this hook.
  • FnContextSendSyncStatic<Fut, ()>, Fut: FutureSendStatic<()> - The hook function to store.
§Returns
  • &Self - A reference to the modified context.
Source

pub async fn try_get_hook<K>(&self, key: K) -> Option<HookHandler<()>>
where K: ToString,

Attempts to retrieve a hook function if it has been set.

§Arguments
  • K: ToString - The key to identify the hook.
§Returns
  • Option<HookHandler<()>> - The hook function if it has been set.
Source

pub async fn get_hook<K>(&self, key: K) -> HookHandler<()>
where K: ToString,

Retrieves a hook function if it has been set, panicking if not found.

§Arguments
  • K: ToString - The key to identify the hook.
§Returns
  • HookHandler<()> - The hook function if it has been set.
§Panics
  • If the hook function is not found.
Source

pub async fn try_send(&self) -> Result<(), ResponseError>

Sends HTTP response data over the stream.

§Returns
  • Result<(), ResponseError> - Result indicating success or failure.
Source

pub async fn send(&self)

Sends HTTP response data over the stream.

§Panics

Panics if the write operation fails.

Source

pub async fn try_send_body(&self) -> Result<(), ResponseError>

Sends HTTP response body.

§Returns
  • Result<(), ResponseError> - Result indicating success or failure.
Source

pub async fn send_body(&self)

Sends HTTP response body.

§Panics

Panics if the write operation fails.

Source

pub async fn try_send_body_with_data<D>( &self, data: D, ) -> Result<(), ResponseError>
where D: AsRef<[u8]>,

Sends only the response body to the client with additional data.

This method is useful for streaming data or for responses where headers have already been sent.

§Arguments
  • AsRef<[u8]> - The additional data to send as the body.
§Returns
  • Result<(), ResponseError> - The result of the send operation.
Source

pub async fn send_body_with_data<D>(&self, data: D)
where D: AsRef<[u8]>,

Sends HTTP response body.

§Arguments
  • AsRef<[u8]> - The response body data (must implement AsRef<u8>).
§Panics

Panics if the write operation fails.

Source

pub async fn try_send_body_list<I, D>( &self, data_iter: I, ) -> Result<(), ResponseError>
where I: IntoIterator<Item = D>, D: AsRef<[u8]>,

Sends multiple HTTP response bodies sequentially.

§Arguments
  • I: IntoIterator<Item = D>, D: AsRef<[u8]> - The response body data list to send.
§Returns
  • Result<(), ResponseError> - Result indicating success or failure.
Source

pub async fn send_body_list<I, D>(&self, data_iter: I)
where I: IntoIterator<Item = D>, D: AsRef<[u8]>,

Sends multiple HTTP response bodies sequentially.

§Arguments
  • I: IntoIterator<Item = D>, D: AsRef<[u8]> - The response body data list to send.
§Panics

Panics if any write operation fails.

Source

pub async fn try_send_body_list_with_data<I, D>( &self, data_iter: I, ) -> Result<(), ResponseError>
where I: IntoIterator<Item = D>, D: AsRef<[u8]>,

Sends a list of response bodies to the client with additional data.

This is useful for streaming multiple data chunks or for responses where headers have already been sent.

§Arguments
  • I: IntoIterator<Item = D>, D: AsRef<[u8]> - The additional data to send as a list of bodies.
§Returns
  • Result<(), ResponseError> - The result of the send operation.
Source

pub async fn send_body_list_with_data<I, D>(&self, data_iter: I)
where I: IntoIterator<Item = D>, D: AsRef<[u8]>,

Sends a list of response bodies to the client with additional data.

§Arguments
  • I: IntoIterator<Item = D>, D: AsRef<[u8]> - The additional data to send as a list of bodies.
§Panics

Panics if any write operation fails.

Source

pub async fn try_flush(&self) -> Result<(), ResponseError>

Flushes the underlying network stream, ensuring all buffered data is sent.

§Returns
  • Result<(), ResponseError> - The result of the flush operation.
Source

pub async fn flush(&self)

Flushes all buffered data to the stream.

§Panics

Panics if the flush operation fails.

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

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 Context

Source§

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

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

impl Default for Context

Source§

fn default() -> Context

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

impl Display for Context

Source§

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

Formats the value using the given formatter. Read more

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> ErasedDestructor for T
where T: 'static,