pub struct Context { /* private fields */ }Expand description
Represents the internal state of the application context.
This structure holds all the data associated with a single request-response cycle, including the stream, request, response, and any custom attributes.
Implementations§
Source§impl Context
Implementation of methods for Context structure.
impl Context
Implementation of methods for Context structure.
Sourcepub async fn http_from_stream(&mut self) -> Result<Request, RequestError>
pub async fn http_from_stream(&mut self) -> Result<Request, RequestError>
Reads an HTTP request from the underlying stream.
§Returns
Result<Request, RequestError>- The parsed request or error.
Sourcepub async fn ws_from_stream(&mut self) -> Result<Request, RequestError>
pub async fn ws_from_stream(&mut self) -> Result<Request, RequestError>
Reads a WebSocket frame from the underlying stream.
§Returns
Result<Request, RequestError>- The parsed frame or error.
Sourcepub fn is_terminated(&self) -> bool
pub 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.
Sourcepub async fn try_get_socket_addr(&self) -> Option<SocketAddr>
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.
Sourcepub async fn get_socket_addr(&self) -> SocketAddr
pub async fn get_socket_addr(&self) -> SocketAddr
Sourcepub async fn try_get_socket_addr_string(&self) -> Option<String>
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.
Sourcepub async fn get_socket_addr_string(&self) -> String
pub async fn get_socket_addr_string(&self) -> String
Sourcepub async fn try_get_socket_host(&self) -> Option<SocketHost>
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.
Sourcepub async fn get_socket_host(&self) -> SocketHost
pub async fn get_socket_host(&self) -> SocketHost
Sourcepub async fn try_get_socket_port(&self) -> Option<SocketPort>
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.
Sourcepub async fn get_socket_port(&self) -> SocketPort
pub async fn get_socket_port(&self) -> SocketPort
Sourcepub fn try_get_route_param<T>(&self, name: T) -> Option<String>
pub fn try_get_route_param<T>(&self, name: T) -> Option<String>
Sourcepub fn get_route_param<T>(&self, name: T) -> String
pub fn get_route_param<T>(&self, name: T) -> String
Sourcepub fn try_get_attribute<V>(&self, key: impl AsRef<str>) -> Option<V>where
V: AnySendSyncClone,
pub fn try_get_attribute<V>(&self, key: impl AsRef<str>) -> Option<V>where
V: AnySendSyncClone,
Sourcepub fn get_attribute<V>(&self, key: impl AsRef<str>) -> Vwhere
V: AnySendSyncClone,
pub fn get_attribute<V>(&self, key: impl AsRef<str>) -> Vwhere
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
AnySendSyncClone- The attribute value if it exists and can be cast to the specified type.
§Panics
- If the attribute is not found.
Sourcepub fn set_attribute<K, V>(&mut self, key: K, value: V) -> &mut Self
pub fn set_attribute<K, V>(&mut self, key: K, value: V) -> &mut Self
Sourcepub fn remove_attribute<K>(&mut self, key: K) -> &mut Self
pub fn remove_attribute<K>(&mut self, key: K) -> &mut Self
Sourcepub fn clear_attribute(&mut self) -> &mut Self
pub fn clear_attribute(&mut self) -> &mut Self
Sourcepub fn try_get_task_panic_data(&self) -> Option<PanicData>
pub fn try_get_task_panic_data(&self) -> Option<PanicData>
Retrieves panic data associated with the current task.
§Returns
Option<PanicData>- Task panic data if a panic was caught during execution.
Sourcepub fn get_task_panic_data(&self) -> PanicData
pub fn get_task_panic_data(&self) -> PanicData
Sourcepub fn try_get_request_error_data(&self) -> Option<RequestError>
pub fn try_get_request_error_data(&self) -> Option<RequestError>
Retrieves request error information if an error occurred during handling.
§Returns
Option<RequestError>- The request error information if an error was caught.
Sourcepub fn get_request_error_data(&self) -> RequestError
pub fn get_request_error_data(&self) -> RequestError
Sourcepub async fn try_send(&mut self) -> Result<(), ResponseError>
pub async fn try_send(&mut self) -> Result<(), ResponseError>
Sends HTTP response data over the stream.
§Returns
Result<(), ResponseError>- Result indicating success or failure.
Sourcepub async fn try_send_body(&self) -> Result<(), ResponseError>
pub async fn try_send_body(&self) -> Result<(), ResponseError>
Sends HTTP response body.
§Returns
Result<(), ResponseError>- Result indicating success or failure.
Sourcepub async fn try_send_body_with_data<D>(
&self,
data: D,
) -> Result<(), ResponseError>
pub async fn try_send_body_with_data<D>( &self, data: D, ) -> Result<(), ResponseError>
Sourcepub async fn send_body_with_data<D>(&self, data: D)
pub async fn send_body_with_data<D>(&self, data: D)
Sourcepub async fn try_send_body_list<I, D>(
&self,
data_iter: I,
) -> Result<(), ResponseError>
pub async fn try_send_body_list<I, D>( &self, data_iter: I, ) -> Result<(), ResponseError>
Sourcepub async fn send_body_list<I, D>(&self, data_iter: I)
pub async fn send_body_list<I, D>(&self, data_iter: I)
Sourcepub async fn try_send_body_list_with_data<I, D>(
&self,
data_iter: I,
) -> Result<(), ResponseError>
pub async fn try_send_body_list_with_data<I, D>( &self, data_iter: I, ) -> Result<(), ResponseError>
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.
Sourcepub async fn send_body_list_with_data<I, D>(&self, data_iter: I)
pub async fn send_body_list_with_data<I, D>(&self, data_iter: I)
Source§impl Context
impl Context
pub fn get_aborted(&self) -> bool
pub fn get_mut_aborted(&mut self) -> &mut bool
pub fn set_aborted(&mut self, val: bool) -> &mut Self
pub fn get_closed(&self) -> bool
pub fn get_mut_closed(&mut self) -> &mut bool
pub fn set_closed(&mut self, val: bool) -> &mut Self
pub fn get_request(&self) -> &Request
pub fn get_response(&self) -> &Response
pub fn get_mut_response(&mut self) -> &mut Response
pub fn set_response(&mut self, val: Response) -> &mut Self
pub fn get_route_params(&self) -> &RouteParams
pub fn get_attributes(&self) -> &ThreadSafeAttributeStore
pub fn get_server(&self) -> &ArcServer
Trait Implementations§
Source§impl From<&ArcRwLockStream> for Context
Implementation of From trait for converting &ArcRwLockStream into Context.
impl From<&ArcRwLockStream> for Context
Implementation of From trait for converting &ArcRwLockStream into Context.
Source§impl From<ArcRwLockStream> for Context
Implementation of From trait for converting ArcRwLockStream into Context.
impl From<ArcRwLockStream> for Context
Implementation of From trait for converting ArcRwLockStream into Context.
Source§impl PartialEq for Context
Implementation of PartialEq trait for Context.
impl PartialEq for Context
Implementation of PartialEq trait for Context.
impl Eq for Context
Implementation of Eq trait for Context.