pub enum HttpConnection<K, IO>{
Http1(Pooled<K, Http1Connection<IO>>),
Http2(Http2Connection),
}
Expand description
A unified representation of an HTTP connection, supporting both HTTP/1.1 and HTTP/2 protocols.
This enum is designed to work with monoio’s native IO traits, which are optimized for io_uring. It allows for efficient handling of both HTTP/1.1 and HTTP/2 connections within the same abstraction.
Variants§
Implementations§
Source§impl<K, IO> HttpConnection<K, IO>
impl<K, IO> HttpConnection<K, IO>
Sourcepub async fn send_request<R, E>(
&mut self,
request: R,
) -> (Result<Response<HttpBody>, HttpError>, bool)
pub async fn send_request<R, E>( &mut self, request: R, ) -> (Result<Response<HttpBody>, HttpError>, bool)
Sends an HTTP request using the appropriate protocol (HTTP/1.1 or HTTP/2).
This method automatically handles the differences between HTTP/1.1 and HTTP/2, providing a unified interface for sending requests.
§Arguments
request
- The HTTP request to send.
§Returns
A tuple containing:
Result<Response<HttpBody>, HttpError>
: The HTTP response or an error.bool
: Indicates whether the connection can be reused (true) or should be closed (false).
§Type Parameters
R
: The request type, which must be convertible into parts with aRequestHead
.E
: The error type for theClientCodec
, which must be convertible intoHttpError
.
§Examples
let (response, can_reuse) = conn.send_request(request).await;
let response: Response<HttpBody> = response?;
Ok(())
}
Trait Implementations§
Source§impl<K, IO> From<Http2Connection> for HttpConnection<K, IO>
impl<K, IO> From<Http2Connection> for HttpConnection<K, IO>
Source§fn from(conn: Http2Connection) -> HttpConnection<K, IO>
fn from(conn: Http2Connection) -> HttpConnection<K, IO>
Converts to this type from the input type.
Source§impl<K, IO> From<Pooled<K, Http1Connection<IO>>> for HttpConnection<K, IO>
impl<K, IO> From<Pooled<K, Http1Connection<IO>>> for HttpConnection<K, IO>
Source§fn from(pooled_conn: Pooled<K, Http1Connection<IO>>) -> HttpConnection<K, IO>
fn from(pooled_conn: Pooled<K, Http1Connection<IO>>) -> HttpConnection<K, IO>
Converts to this type from the input type.
Source§impl<K, IO> Poolable for HttpConnection<K, IO>
impl<K, IO> Poolable for HttpConnection<K, IO>
Auto Trait Implementations§
impl<K, IO> Freeze for HttpConnection<K, IO>where
K: Freeze,
impl<K, IO> !RefUnwindSafe for HttpConnection<K, IO>
impl<K, IO> !Send for HttpConnection<K, IO>
impl<K, IO> !Sync for HttpConnection<K, IO>
impl<K, IO> Unpin for HttpConnection<K, IO>where
K: Unpin,
impl<K, IO> !UnwindSafe for HttpConnection<K, IO>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more