pub enum Connection<'b, T, const N: usize = DEFAULT_MAX_HEADERS_COUNT>where
T: TcpConnect,{
Transition(TransitionState),
Unbound(UnboundState<'b, T, N>),
Request(RequestState<'b, T, N>),
Response(ResponseState<'b, T, N>),
}Expand description
A client connection that can be used to send HTTP requests and receive responses.
Variants§
Transition(TransitionState)
Unbound(UnboundState<'b, T, N>)
Request(RequestState<'b, T, N>)
Response(ResponseState<'b, T, N>)
Implementations§
Source§impl<'b, T, const N: usize> Connection<'b, T, N>where
T: TcpConnect,
impl<'b, T, const N: usize> Connection<'b, T, N>where
T: TcpConnect,
Sourcepub fn new(buf: &'b mut [u8], socket: &'b T, addr: SocketAddr) -> Self
pub fn new(buf: &'b mut [u8], socket: &'b T, addr: SocketAddr) -> Self
Create a new client connection.
Note that the connection does not have any built-in read/write timeouts:
- To add a timeout on each IO operation, wrap the
sockettype with theedge_nal::WithTimeoutwrapper. - To add a global request-response timeout, wrap your complete request-response processing
logic with the
edge_nal::with_timeoutfunction.
Parameters:
buf: A buffer to use for reading and writing data.socket: The TCP stack to use for the connection.addr: The address of the server to connect to.
Sourcepub async fn reinitialize(
&mut self,
addr: SocketAddr,
) -> Result<(), Error<T::Error>>
pub async fn reinitialize( &mut self, addr: SocketAddr, ) -> Result<(), Error<T::Error>>
Reinitialize the connection with a new address.
Sourcepub async fn initiate_request(
&mut self,
http11: bool,
method: Method,
uri: &str,
headers: &[(&str, &str)],
) -> Result<(), Error<T::Error>>
pub async fn initiate_request( &mut self, http11: bool, method: Method, uri: &str, headers: &[(&str, &str)], ) -> Result<(), Error<T::Error>>
Initiate an HTTP request.
Sourcepub async fn initiate_ws_upgrade_request(
&mut self,
host: Option<&str>,
origin: Option<&str>,
uri: &str,
version: Option<&str>,
nonce: &[u8; 16],
nonce_base64_buf: &mut [u8; 28],
) -> Result<(), Error<T::Error>>
pub async fn initiate_ws_upgrade_request( &mut self, host: Option<&str>, origin: Option<&str>, uri: &str, version: Option<&str>, nonce: &[u8; 16], nonce_base64_buf: &mut [u8; 28], ) -> Result<(), Error<T::Error>>
A utility method to initiate a WebSocket upgrade request.
Sourcepub fn is_request_initiated(&self) -> bool
pub fn is_request_initiated(&self) -> bool
Return true if a request has been initiated.
Sourcepub async fn initiate_response(&mut self) -> Result<(), Error<T::Error>>
pub async fn initiate_response(&mut self) -> Result<(), Error<T::Error>>
Initiate an HTTP response.
This should be called after a request has been initiated and the request body had been sent.
Sourcepub fn is_response_initiated(&self) -> bool
pub fn is_response_initiated(&self) -> bool
Return true if a response has been initiated.
Sourcepub fn is_ws_upgrade_accepted(
&self,
nonce: &[u8; 16],
buf: &mut [u8; 33],
) -> Result<bool, Error<T::Error>>
pub fn is_ws_upgrade_accepted( &self, nonce: &[u8; 16], buf: &mut [u8; 33], ) -> Result<bool, Error<T::Error>>
Return true if the server accepted the WebSocket upgrade request.
Sourcepub fn split(
&mut self,
) -> (&ResponseHeaders<'b, N>, &mut Body<'b, T::Socket<'b>>)
pub fn split( &mut self, ) -> (&ResponseHeaders<'b, N>, &mut Body<'b, T::Socket<'b>>)
Split the connection into its headers and body parts.
The connection must be in response mode.
Sourcepub fn headers(&self) -> Result<&ResponseHeaders<'b, N>, Error<T::Error>>
pub fn headers(&self) -> Result<&ResponseHeaders<'b, N>, Error<T::Error>>
Get the headers of the response.
The connection must be in response mode.
Sourcepub fn raw_connection(&mut self) -> Result<&mut T::Socket<'b>, Error<T::Error>>
pub fn raw_connection(&mut self) -> Result<&mut T::Socket<'b>, Error<T::Error>>
Get a mutable reference to the raw connection.
This can be used to send raw data over the connection.
Sourcepub fn release(self) -> (T::Socket<'b>, &'b mut [u8])
pub fn release(self) -> (T::Socket<'b>, &'b mut [u8])
Release the connection, returning the raw connection and the buffer.
Sourcepub async fn complete(&mut self) -> Result<(), Error<T::Error>>
pub async fn complete(&mut self) -> Result<(), Error<T::Error>>
Complete the request-response cycle
If the request has not been initiated, this method will do nothing. If the response has not been initiated, it will be initiated and will be consumed.
pub async fn close(self) -> Result<(), Error<T::Error>>
Sourcepub fn needs_close(&self) -> bool
pub fn needs_close(&self) -> bool
Return true if the connection needs to be closed (i.e. the server has requested it or the connection is in an invalid state)
Trait Implementations§
Source§impl<T, const N: usize> ErrorType for Connection<'_, T, N>where
T: TcpConnect,
impl<T, const N: usize> ErrorType for Connection<'_, T, N>where
T: TcpConnect,
Source§impl<T, const N: usize> Read for Connection<'_, T, N>where
T: TcpConnect,
impl<T, const N: usize> Read for Connection<'_, T, N>where
T: TcpConnect,
Source§async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
Source§async fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf. Read more