use std::time::Duration;
use hyper::client::conn::http2::Builder;
use hyper_util::rt::TokioExecutor;
pub struct Config {
keep_alive_interval: Option<Duration>,
keep_alive_timeout: Duration,
keep_alive_while_idle: bool,
}
impl Default for Config {
fn default() -> Self {
Self {
keep_alive_interval: None,
keep_alive_timeout: Duration::from_secs(20),
keep_alive_while_idle: false,
}
}
}
impl Config {
pub fn set_keep_alive_interval<D>(&mut self, interval: D) -> &mut Self
where
D: Into<Option<Duration>>,
{
self.keep_alive_interval = interval.into();
self
}
pub fn set_keep_alive_timeout(&mut self, timeout: Duration) -> &mut Self {
self.keep_alive_timeout = timeout;
self
}
pub fn set_keep_alive_while_idle(&mut self, enabled: bool) -> &mut Self {
self.keep_alive_while_idle = enabled;
self
}
}
pub(crate) fn client(config: &Config) -> Builder<TokioExecutor> {
let mut builder = Builder::new(TokioExecutor::new());
builder
.keep_alive_interval(config.keep_alive_interval)
.keep_alive_timeout(config.keep_alive_timeout)
.keep_alive_while_idle(config.keep_alive_while_idle);
builder
}