use super::service::RequestDecompression;
use crate::headers::encoding::AcceptEncoding;
use rama_core::Layer;
#[derive(Debug, Default, Clone)]
pub struct RequestDecompressionLayer {
accept: AcceptEncoding,
pass_through_unaccepted: bool,
}
impl<S> Layer<S> for RequestDecompressionLayer {
type Service = RequestDecompression<S>;
fn layer(&self, service: S) -> Self::Service {
RequestDecompression {
inner: service,
accept: self.accept,
pass_through_unaccepted: self.pass_through_unaccepted,
}
}
}
impl RequestDecompressionLayer {
#[must_use]
pub fn new() -> Self {
Default::default()
}
rama_utils::macros::generate_set_and_with! {
pub fn gzip(mut self, enable: bool) -> Self {
self.accept.set_gzip(enable);
self
}
}
rama_utils::macros::generate_set_and_with! {
pub fn deflate(mut self, enable: bool) -> Self {
self.accept.set_deflate(enable);
self
}
}
rama_utils::macros::generate_set_and_with! {
pub fn br(mut self, enable: bool) -> Self {
self.accept.set_br(enable);
self
}
}
rama_utils::macros::generate_set_and_with! {
pub fn zstd(mut self, enable: bool) -> Self {
self.accept.set_zstd(enable);
self
}
}
rama_utils::macros::generate_set_and_with! {
pub fn pass_through_unaccepted(mut self, enable: bool) -> Self {
self.pass_through_unaccepted = enable;
self
}
}
}