use std::marker::PhantomData;
use std::net::SocketAddr;
use std::time::Duration;
use crate::runtime::Runtime;
pub(crate) enum HttpConnection {
H1(hyper::client::conn::http1::SendRequest<crate::error::AioductBody>),
H2(hyper::client::conn::http2::SendRequest<crate::error::AioductBody>),
#[cfg(all(feature = "http3", feature = "rustls"))]
H3(h3::client::SendRequest<h3_quinn::OpenStreams, bytes::Bytes>),
}
pub(crate) struct PooledConnection<R: Runtime> {
pub(crate) conn: HttpConnection,
pub(crate) remote_addr: Option<SocketAddr>,
pub(crate) tls_info: Option<crate::tls::TlsInfo>,
pub(crate) tls_handshake_duration: Option<Duration>,
pub(crate) sans: Vec<String>,
_runtime: PhantomData<R>,
}
impl<R: Runtime> PooledConnection<R> {
pub(crate) fn new_h1(
sender: hyper::client::conn::http1::SendRequest<crate::error::AioductBody>,
) -> Self {
Self {
conn: HttpConnection::H1(sender),
remote_addr: None,
tls_info: None,
tls_handshake_duration: None,
sans: Vec::new(),
_runtime: PhantomData,
}
}
pub(crate) fn new_h2(
sender: hyper::client::conn::http2::SendRequest<crate::error::AioductBody>,
) -> Self {
Self {
conn: HttpConnection::H2(sender),
remote_addr: None,
tls_info: None,
tls_handshake_duration: None,
sans: Vec::new(),
_runtime: PhantomData,
}
}
#[cfg(all(feature = "http3", feature = "rustls"))]
pub(crate) fn new_h3(
sender: h3::client::SendRequest<h3_quinn::OpenStreams, bytes::Bytes>,
) -> Self {
Self {
conn: HttpConnection::H3(sender),
remote_addr: None,
tls_info: None,
tls_handshake_duration: None,
sans: Vec::new(),
_runtime: PhantomData,
}
}
pub(crate) fn is_ready(&self) -> bool {
match &self.conn {
HttpConnection::H1(s) => s.is_ready(),
HttpConnection::H2(s) => s.is_ready(),
#[cfg(all(feature = "http3", feature = "rustls"))]
HttpConnection::H3(_) => true,
}
}
pub(crate) fn is_h2_or_h3(&self) -> bool {
match &self.conn {
HttpConnection::H1(_) => false,
HttpConnection::H2(_) => true,
#[cfg(all(feature = "http3", feature = "rustls"))]
HttpConnection::H3(_) => true,
}
}
}