use async_trait::async_trait;
use std::time::Duration;
use pingora_error::Result;
use crate::{
protocols::{http::custom::client::Session, Stream},
upstreams::peer::Peer,
};
pub enum Connection<S: Session> {
Session(S),
Stream(Stream),
}
#[doc(hidden)]
#[async_trait]
pub trait Connector: Send + Sync + Unpin + 'static {
type Session: Session;
async fn get_http_session<P: Peer + Send + Sync + 'static>(
&self,
peer: &P,
) -> Result<(Connection<Self::Session>, bool)>;
async fn reused_http_session<P: Peer + Send + Sync + 'static>(
&self,
peer: &P,
) -> Option<Self::Session>;
async fn release_http_session<P: Peer + Send + Sync + 'static>(
&self,
mut session: Self::Session,
peer: &P,
idle_timeout: Option<Duration>,
);
}
#[doc(hidden)]
#[async_trait]
impl Connector for () {
type Session = ();
async fn get_http_session<P: Peer + Send + Sync + 'static>(
&self,
_peer: &P,
) -> Result<(Connection<Self::Session>, bool)> {
unreachable!("connector: get_http_session")
}
async fn reused_http_session<P: Peer + Send + Sync + 'static>(
&self,
_peer: &P,
) -> Option<Self::Session> {
unreachable!("connector: reused_http_session")
}
async fn release_http_session<P: Peer + Send + Sync + 'static>(
&self,
_session: Self::Session,
_peer: &P,
_idle_timeout: Option<Duration>,
) {
unreachable!("connector: release_http_session")
}
}