pub struct Stream {
pub stream: Box<dyn Transport>,
/* private fields */
}Fields§
§stream: Box<dyn Transport>The bidirectional byte pipe the request/response cycle runs over.
The concrete type is erased behind Transport, so a plain TCP socket, a
TLS session and a per-request duplex stream are interchangeable here.
Address metadata comes from the transport itself, so a transport without
a socket identity reports an error instead of a fabricated address.
Implementations§
Source§impl Stream
Inherent implementation of Stream.
impl Stream
Inherent implementation of Stream.
Sourcepub fn from_transport<T>(
transport: T,
request_config: RequestConfig,
closed: bool,
) -> Streamwhere
T: Transport + 'static,
pub fn from_transport<T>(
transport: T,
request_config: RequestConfig,
closed: bool,
) -> Streamwhere
T: Transport + 'static,
Boxes a transport into a Stream for the request pipeline.
This is the single construction path: a plain TCP socket, a TLS session
and a per-request duplex stream all enter here, so nothing above the
transport line has to know which one it is serving. The transport is
type erased immediately, which keeps Stream a fixed size regardless of
the concrete protocol adapter behind it.
§Arguments
T- The transport type to serve the request cycle over.RequestConfig- The parsing limits and read timeout for the cycle.bool- Whether the connection starts already closed.
§Returns
Self- A stream serving bytes through the boxed transport.
Sourcepub fn new(
stream: TcpStream,
request_config: RequestConfig,
closed: bool,
) -> Stream
pub fn new( stream: TcpStream, request_config: RequestConfig, closed: bool, ) -> Stream
Boxes a TCP socket into a Stream for the request pipeline.
Kept as the socket-facing constructor so the accept loop keeps its
existing call shape; it delegates to from_transport, so there is one
construction path rather than two.
§Arguments
TcpStream- The accepted socket to serve the request cycle over.RequestConfig- The parsing limits and read timeout for the cycle.bool- Whether the connection starts already closed.
§Returns
Self- A stream serving bytes through the boxed socket.
Sourcepub fn get_peer_addr(&self) -> Result<SocketAddr, Error>
pub fn get_peer_addr(&self) -> Result<SocketAddr, Error>
Reports the address of the remote end of the transport.
Delegates to the transport itself, so a transport without a socket identity answers with an error rather than a fabricated address.
§Returns
Result<SocketAddr, io::Error>- The peer address reported by the transport.
Sourcepub fn get_local_addr(&self) -> Result<SocketAddr, Error>
pub fn get_local_addr(&self) -> Result<SocketAddr, Error>
Reports the address of the local end of the transport.
Delegates to the transport itself, so a transport without a socket identity answers with an error rather than a fabricated address.
§Returns
Result<SocketAddr, io::Error>- The local address reported by the transport.
Sourcepub fn is_keep_alive(&self, keep_alive: bool) -> bool
pub 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.
Sourcepub async fn try_fill_http_request(
&mut self,
request: &mut Request,
) -> Result<(), RequestError>
pub async fn try_fill_http_request( &mut self, request: &mut Request, ) -> Result<(), RequestError>
Parses an HTTP request from a TCP stream into the given request.
The request is reset and filled in place, reusing its allocations. If the timeout is DEFAULT_LOW_SECURITY_READ_TIMEOUT_MS, no timeout is applied.
§Arguments
&mut Request- The request object to reset and fill.
§Returns
Result<(), RequestError>- Ok on success, or an error if parsing fails.
Sourcepub async fn try_get_http_request(&mut self) -> Result<Request, RequestError>
pub async fn try_get_http_request(&mut self) -> 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_READ_TIMEOUT_MS, no timeout is applied.
§Returns
Result<Request, RequestError>- The parsed request or an error.
Sourcepub async fn try_get_websocket_request(
&mut self,
) -> Result<Vec<u8>, RequestError>
pub async fn try_get_websocket_request( &mut self, ) -> Result<Vec<u8>, 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_READ_TIMEOUT_MS, no timeout is applied.
§Returns
Result<RequestBody, RequestError>- The parsed WebSocket request or an error.
Sourcepub async fn try_send<D>(&mut self, data: D) -> Result<(), ResponseError>
pub async fn try_send<D>(&mut self, data: D) -> Result<(), ResponseError>
Sourcepub async fn try_send_list<I, D>(
&mut self,
data_iter: I,
) -> Result<(), ResponseError>
pub async fn try_send_list<I, D>( &mut self, data_iter: I, ) -> Result<(), ResponseError>
Source§impl Stream
impl Stream
pub fn get_stream(&self) -> &Box<dyn Transport>
pub fn get_mut_stream(&mut self) -> &mut Box<dyn Transport>
pub fn set_stream(&mut self, val: Box<dyn Transport>) -> &mut Stream
pub fn get_request_config(&self) -> &RequestConfig
pub fn get_closed(&self) -> bool
pub fn set_closed(&mut self, val: bool) -> &mut Stream
pub fn get_leftover(&self) -> &Vec<u8> ⓘ
pub fn get_leftover_start(&self) -> usize
pub fn get_leftover_end(&self) -> usize
pub fn get_line_buffer(&self) -> &String
pub fn get_header_line_buffer(&self) -> &String
Trait Implementations§
Source§impl From<usize> for &'static Stream
Implementation of From trait for converting usize address into &Stream.
impl From<usize> for &'static Stream
Implementation of From trait for converting usize address into &Stream.
Source§fn from(address: usize) -> &'static Stream
fn from(address: usize) -> &'static Stream
Converts a memory address into a reference to Stream.
§Arguments
usize- The memory address of theStreaminstance.
§Returns
&'static Stream- A reference to theStreamat the given address.
§Safety
- The address is guaranteed to be a valid
Streaminstance that was previously converted from a reference and is managed by the runtime.
Source§impl<'a> From<usize> for &'a mut Stream
Implementation of From trait for converting usize address into &mut Stream.
impl<'a> From<usize> for &'a mut Stream
Implementation of From trait for converting usize address into &mut Stream.
Source§fn from(address: usize) -> &'a mut Stream
fn from(address: usize) -> &'a mut Stream
Converts a memory address into a mutable reference to Stream.
§Arguments
usize- The memory address of theStreaminstance.
§Returns
&'a mut Stream- A mutable reference to theStreamat the given address.
§Safety
- The address is guaranteed to be a valid
Streaminstance that was previously converted from a reference and is managed by the runtime.