tower_http_cache_plus/cache/middleware/
configuration.rs1use super::{super::configuration::*, hooks::*};
2
3use kutil::http::*;
4
5pub const ENCODINGS_BY_PREFERENCE: &[EncodingHeaderValue] = &[
12 EncodingHeaderValue::Brotli,
13 EncodingHeaderValue::GZip,
14 EncodingHeaderValue::Deflate,
15 EncodingHeaderValue::Zstandard,
16];
17
18pub struct MiddlewareCachingConfiguration<RequestBodyT, CacheT, CacheKeyT> {
24 pub cache: Option<CacheT>,
26
27 pub cacheable_by_request: Option<CacheableHook>,
29
30 pub cacheable_by_response: Option<CacheableHook>,
32
33 pub cache_key: Option<CacheKeyHook<CacheKeyT, RequestBodyT>>,
35
36 pub inner: CachingConfiguration,
38}
39
40impl<RequestBodyT, CacheT, CacheKeyT> Default
41 for MiddlewareCachingConfiguration<RequestBodyT, CacheT, CacheKeyT>
42{
43 fn default() -> Self {
44 Self {
45 cache: None,
46 cacheable_by_request: None,
47 cacheable_by_response: None,
48 cache_key: None,
49 inner: CachingConfiguration {
50 min_body_size: 0,
51 max_body_size: 1024 * 1024, cacheable_by_default: true,
53 cache_duration: None,
54 },
55 }
56 }
57}
58
59impl<RequestBodyT, CacheT, CacheKeyT> Clone
60 for MiddlewareCachingConfiguration<RequestBodyT, CacheT, CacheKeyT>
61where
62 CacheT: Clone,
63{
64 fn clone(&self) -> Self {
65 Self {
68 cache: self.cache.clone(),
69 cacheable_by_request: self.cacheable_by_request.clone(),
70 cacheable_by_response: self.cacheable_by_response.clone(),
71 cache_key: self.cache_key.clone(),
72 inner: self.inner.clone(),
73 }
74 }
75}
76
77#[derive(Clone)]
83pub struct MiddlewareEncodingConfiguration {
84 pub enabled_encodings_by_preference: Option<Vec<EncodingHeaderValue>>,
86
87 pub encodable_by_request: Option<EncodableHook>,
89
90 pub encodable_by_response: Option<EncodableHook>,
92
93 pub inner: EncodingConfiguration,
95}
96
97impl Default for MiddlewareEncodingConfiguration {
98 fn default() -> Self {
99 Self {
100 enabled_encodings_by_preference: Some(ENCODINGS_BY_PREFERENCE.into()),
101 encodable_by_request: None,
102 encodable_by_response: None,
103 inner: EncodingConfiguration {
104 min_body_size: 0,
105 encodable_by_default: true,
106 keep_identity_encoding: true,
107 },
108 }
109 }
110}