mod handshake;
use self::handshake::Handshaker;
use super::{options::ConnectionPoolOptions, Connection};
use crate::{client::auth::Credential, error::Result, runtime::HttpClient};
#[derive(Debug)]
pub(super) struct ConnectionEstablisher {
handshaker: Handshaker,
http_client: HttpClient,
credential: Option<Credential>,
}
impl ConnectionEstablisher {
pub(super) fn new(http_client: HttpClient, options: Option<&ConnectionPoolOptions>) -> Self {
let handshaker = Handshaker::new(options);
Self {
handshaker,
http_client,
credential: options.and_then(|options| options.credential.clone()),
}
}
pub(super) async fn establish_connection(&self, connection: &mut Connection) -> Result<()> {
self.handshaker.handshake(connection).await?;
if let Some(ref credential) = self.credential {
credential
.authenticate_stream(connection, &self.http_client)
.await?;
}
Ok(())
}
}