use super::HttpProxyConnector;
use rama_core::Layer;
use rama_http_types::Version;
#[derive(Debug, Clone, Default)]
pub struct HttpProxyConnectorLayer {
required: bool,
version: Option<Version>,
}
impl HttpProxyConnectorLayer {
pub fn optional() -> Self {
Self {
required: false,
version: Some(Version::HTTP_11),
}
}
pub fn required() -> Self {
Self {
required: true,
version: Some(Version::HTTP_11),
}
}
pub fn with_version(mut self, version: Version) -> Self {
self.version = Some(version);
self
}
pub fn set_version(&mut self, version: Version) -> &mut Self {
self.version = Some(version);
self
}
pub fn with_auto_version(mut self) -> Self {
self.version = None;
self
}
pub fn set_auto_version(&mut self) -> &mut Self {
self.version = None;
self
}
}
impl<S> Layer<S> for HttpProxyConnectorLayer {
type Service = HttpProxyConnector<S>;
fn layer(&self, inner: S) -> Self::Service {
let mut svc = HttpProxyConnector::new(inner, self.required);
match self.version {
Some(version) => svc.set_version(version),
None => svc.set_auto_version(),
};
svc
}
}