monoio_transports::http

Struct HttpConnector

Source
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 default TlsConnector sets the client’s ALPN advertisement to h2 and http/1.1.

  • For plain text HTTP, the default protocol is HTTP/1.1 unless th/// client to a particular protocol.

Connector TypeProtocolMethodExampleDescription
TlsConnectorHTTP/1.1 and HTTP/2default()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.
TcpConnectorHTTP/1.1build_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.
TcpConnectorHTTP/2build_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.
TlsConnectorHTTP/1.1build_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.
TlsConnectorHTTP/2build_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>

Source

pub fn new(connector: C) -> Self

Source

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

Source

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();
Source

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();
Source

pub fn h2_builder(&mut self) -> &mut MonoioH2Builder

Source

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 old HttpConnector instance.
  • new: A mutable reference to the new HttpConnector 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>

Source

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();
Source

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>

Source

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();
Source

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>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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,

Source§

type Connection = HttpConnection<K, IO>

Source§

type Error = TransportError

Source§

async fn connect(&self, key: K) -> Result<Self::Connection, Self::Error>

Attempts to establish a connection. Read more
Source§

impl<C: Default, K: 'static, IO: AsyncWriteRent + 'static> Default for HttpConnector<C, K, IO>

Source§

fn default() -> Self

Creates a new HttpConnector with the default configuration.

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>
where C: Unpin, K: Unpin,

§

impl<C, K, IO> !UnwindSafe for HttpConnector<C, K, IO>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<K, T> ConnectorExt<K> for T
where T: Connector<K>,

Source§

fn connect_with_timeout( &self, key: K, timeout: Duration, ) -> impl Future<Output = Result<Result<<T as Connector<K>>::Connection, <T as Connector<K>>::Error>, Elapsed>>

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Param<T> for T
where T: Clone,

Source§

fn param(&self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more