use super::{super::configuration::*, hooks::*};
use kutil::http::*;
pub const ENCODINGS_BY_PREFERENCE: &[EncodingHeaderValue] = &[
EncodingHeaderValue::Brotli,
EncodingHeaderValue::GZip,
EncodingHeaderValue::Deflate,
EncodingHeaderValue::Zstandard,
];
pub struct MiddlewareCachingConfiguration<RequestBodyT, CacheT, CacheKeyT> {
pub cache: Option<CacheT>,
pub cacheable_by_request: Option<CacheableHook>,
pub cacheable_by_response: Option<CacheableHook>,
pub cache_key: Option<CacheKeyHook<CacheKeyT, RequestBodyT>>,
pub inner: CachingConfiguration,
}
impl<RequestBodyT, CacheT, CacheKeyT> Default
for MiddlewareCachingConfiguration<RequestBodyT, CacheT, CacheKeyT>
{
fn default() -> Self {
Self {
cache: None,
cacheable_by_request: None,
cacheable_by_response: None,
cache_key: None,
inner: CachingConfiguration {
min_body_size: 0,
max_body_size: 1024 * 1024, cacheable_by_default: true,
cache_duration: None,
},
}
}
}
impl<RequestBodyT, CacheT, CacheKeyT> Clone
for MiddlewareCachingConfiguration<RequestBodyT, CacheT, CacheKeyT>
where
CacheT: Clone,
{
fn clone(&self) -> Self {
Self {
cache: self.cache.clone(),
cacheable_by_request: self.cacheable_by_request.clone(),
cacheable_by_response: self.cacheable_by_response.clone(),
cache_key: self.cache_key.clone(),
inner: self.inner.clone(),
}
}
}
#[derive(Clone)]
pub struct MiddlewareEncodingConfiguration {
pub enabled_encodings_by_preference: Option<Vec<EncodingHeaderValue>>,
pub encodable_by_request: Option<EncodableHook>,
pub encodable_by_response: Option<EncodableHook>,
pub inner: EncodingConfiguration,
}
impl Default for MiddlewareEncodingConfiguration {
fn default() -> Self {
Self {
enabled_encodings_by_preference: Some(ENCODINGS_BY_PREFERENCE.into()),
encodable_by_request: None,
encodable_by_response: None,
inner: EncodingConfiguration {
min_body_size: 0,
encodable_by_default: true,
keep_identity_encoding: true,
},
}
}
}