pub struct HttpConnector<C, K, IO: AsyncWriteRent> {
pub read_timeout: Option<Duration>,
/* private fields */
}
Expand description
HttpConnector
is a universal connector supporting both HTTP/1.1 and HTTP/2 protocols,
designed for use with monoio’s native IO traits which work with io_uring.
It can be used with a TlsConnector
for HTTPS connections.
§Protocol Selection
T///
-
When used with a
TlsConnector
, the protocol is determined by the ALPN negotiation. The defaultTlsConnector
sets the client’s ALPN advertisement toh2
andhttp/1.1
. -
For plain text HTTP, the default protocol is HTTP/1.1 unless th/// client to a particular protocol.
Connector Type | Protocol | Method | Example | Description |
---|---|---|---|---|
TlsConnector | HTTP/1.1 and HTTP/2 | default() | rust<br>let connector: HttpConnector<TlsConnector<TcpConnector>, _, _> = HttpConnector::default();<br> | Creates a HttpConnector that supports both HTTP/1.1 and HTTP/2, leveraging monoio’s io_uring capabilities. |
TcpConnector | HTTP/1.1 | build_tcp_http1_only() | rust<br>let connector = HttpConnector::build_tcp_http1_only();<br> | Creates an HttpConnector that only supports HTTP/1.1 over TCP, using monoio’s native IO traits. |
TcpConnector | HTTP/2 | build_tcp_http2_only() | rust<br>let connector = HttpConnector::build_tcp_http2_only();<br> | Creates an HttpConnector that only supports HTTP/2 over TCP, optimized for io_uring. |
TlsConnector | HTTP/1.1 | build_tls_http1_only() | rust<br>let connector = HttpConnector::build_tls_http1_only();<br> | Creates an HttpConnector with a TlsConnector that only supports HTTP/1.1, using monoio’s efficient I/O operations. |
TlsConnector | HTTP/2 | build_tls_http2_only() | rust<br>let connector = HttpConnector::build_tls_http2_only();<br> | Creates an HttpConnector with a TlsConnector that only supports HTTP/2, fully utilizing io_uring’s performance benefits. |
Note: This connector is specifically designed to work with monoio’s native IO traits, which are built on top of io_uring. This ensures optimal performance and efficiency when used within a monoio-based application.
Fields§
§read_timeout: Option<Duration>
Implementations§
Source§impl<C, K: 'static, IO: AsyncWriteRent + 'static> HttpConnector<C, K, IO>
impl<C, K: 'static, IO: AsyncWriteRent + 'static> HttpConnector<C, K, IO>
pub fn new(connector: C) -> Self
Sourcepub fn set_read_timeout(&mut self, timeout: Option<Duration>)
pub fn set_read_timeout(&mut self, timeout: Option<Duration>)
Sets the read timeout for the HttpConnector
.
This method sets the read timeout for HTTP/1.1 connections only
Sourcepub fn set_http1_only(&mut self)
pub fn set_http1_only(&mut self)
Sets the protocol of the HttpConnector
to HTTP/1.1 only.
This method should be used with non-TLS connectors like TcpConnector
, UdsConnector
, etc.
For TLS connectors, use build_tls_http1_only
instead to set the correct ALPN.
§Examples
let mut connector = HttpConnector::new(TcpConnector::new());
connector.set_http1_only();
Sourcepub fn set_http2_only(&mut self)
pub fn set_http2_only(&mut self)
Sets the protocol of the HttpConnector
to HTTP/2 only.
This method should be used with non-TLS connectors like TcpConnector
, UdsConnector
, etc.
For TLS connectors, use build_tls_http2_only
instead to set the correct ALPN.
§Examples
let mut connector = HttpConnector::new(TcpConnector::new());
connector.set_http2_only();
pub fn h2_builder(&mut self) -> &mut MonoioH2Builder
Sourcepub fn transfer_pool(old: &Self, new: &mut Self) -> Result<(), &'static str>
pub fn transfer_pool(old: &Self, new: &mut Self) -> Result<(), &'static str>
Transfers the connection pool from an old HttpConnector
instance to a new one.
This function checks if the protocol and read timeout settings of the old and new
HttpConnector
instances match. If they do, it clones the connection pools from the
old instance to the new instance.
§Parameters
old
: A reference to the oldHttpConnector
instance.new
: A mutable reference to the newHttpConnector
instance.
§Returns
Ok(())
if the pool transfer was successful.Err(&'static str)
if the pool transfer failed due to mismatched protocol or read timeout settings.
§Notes
- If the protocol or read timeout settings do not match between the old and new instances, the function will return early without transferring the connection pools.
Source§impl<K: 'static, IO: AsyncWriteRent + 'static> HttpConnector<TcpConnector, K, IO>
impl<K: 'static, IO: AsyncWriteRent + 'static> HttpConnector<TcpConnector, K, IO>
Sourcepub fn build_tcp_http1_only() -> Self
pub fn build_tcp_http1_only() -> Self
Builds a new HttpConnector
with a TcpConnector
that supports only HTTP/1.1.
This method sets the protocol of the HttpConnector
to HTTP/1.1 only.
§Examples
let connector = HttpConnector::build_tcp_http1_only();
Sourcepub fn build_tcp_http2_only() -> Self
pub fn build_tcp_http2_only() -> Self
Builds a new HttpConnector
with a TcpConnector
that supports only HTTP/2.
This method sets the protocol of the HttpConnector
to HTTP/2 only.
§Examples
let connector = HttpConnector::build_tcp_http2_only();
Source§impl<C: Default, K: 'static, IO: AsyncWriteRent + 'static> HttpConnector<TlsConnector<C>, K, IO>
impl<C: Default, K: 'static, IO: AsyncWriteRent + 'static> HttpConnector<TlsConnector<C>, K, IO>
Sourcepub fn build_tls_http1_only() -> Self
pub fn build_tls_http1_only() -> Self
Builds a new HttpConnector
with a TlsConnector
that supports only HTTP/1.1.
This method sets the client’s ALPN advertisement to http/1.1
.
§Examples
let connector = HttpConnector::build_tls_http1_only();
Sourcepub fn build_tls_http2_only() -> Self
pub fn build_tls_http2_only() -> Self
Builds a new HttpConnector
with a TlsConnector
that supports only HTTP/2.
This method sets the client’s ALPN advertisement to h2
.
§Examples
let connector = HttpConnector::build_tls_http2_only();
Trait Implementations§
Source§impl<C: Clone, K, IO: AsyncWriteRent> Clone for HttpConnector<C, K, IO>
impl<C: Clone, K, IO: AsyncWriteRent> Clone for HttpConnector<C, K, IO>
Source§impl<C, K: Key, IO> Connector<K> for HttpConnector<C, K, IO>where
C: Connector<K, Connection = IO>,
C::Connection: TransportConnMetadata<Metadata = TransportConnMeta>,
TransportError: From<C::Error>,
IO: AsyncReadRent + AsyncWriteRent + Split + Unpin + 'static,
impl<C, K: Key, IO> Connector<K> for HttpConnector<C, K, IO>where
C: Connector<K, Connection = IO>,
C::Connection: TransportConnMetadata<Metadata = TransportConnMeta>,
TransportError: From<C::Error>,
IO: AsyncReadRent + AsyncWriteRent + Split + Unpin + 'static,
type Connection = HttpConnection<K, IO>
type Error = TransportError
Source§impl<C: Default, K: 'static, IO: AsyncWriteRent + 'static> Default for HttpConnector<C, K, IO>
impl<C: Default, K: 'static, IO: AsyncWriteRent + 'static> Default for HttpConnector<C, K, IO>
Auto Trait Implementations§
impl<C, K, IO> !Freeze for HttpConnector<C, K, IO>
impl<C, K, IO> !RefUnwindSafe for HttpConnector<C, K, IO>
impl<C, K, IO> !Send for HttpConnector<C, K, IO>
impl<C, K, IO> !Sync for HttpConnector<C, K, IO>
impl<C, K, IO> Unpin for HttpConnector<C, K, IO>
impl<C, K, IO> !UnwindSafe for HttpConnector<C, 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)