kutil_http/cache/middleware/
configuration.rs1use super::{
2 super::super::{cache::*, headers::*},
3 hooks::*,
4};
5
6pub const ENCODINGS_BY_PREFERENCE: &[EncodingHeaderValue] = &[
13 EncodingHeaderValue::Brotli,
14 EncodingHeaderValue::GZip,
15 EncodingHeaderValue::Deflate,
16 EncodingHeaderValue::Zstandard,
17];
18
19pub struct MiddlewareCachingConfiguration<RequestBodyT, CacheT, CacheKeyT> {
25 pub cache: Option<CacheT>,
27
28 pub cacheable_by_request: Option<CacheableHook>,
30
31 pub cacheable_by_response: Option<CacheableHook>,
33
34 pub cache_key: Option<CacheKeyHook<CacheKeyT, RequestBodyT>>,
36
37 pub inner: CachingConfiguration,
39}
40
41impl<RequestBodyT, CacheT, CacheKeyT> Default for MiddlewareCachingConfiguration<RequestBodyT, CacheT, CacheKeyT> {
42 fn default() -> Self {
43 Self {
44 cache: None,
45 cacheable_by_request: None,
46 cacheable_by_response: None,
47 cache_key: None,
48 inner: CachingConfiguration {
49 min_body_size: 0,
50 max_body_size: 1024 * 1024, cacheable_by_default: true,
52 cache_duration: None,
53 },
54 }
55 }
56}
57
58impl<RequestBodyT, CacheT, CacheKeyT> Clone for MiddlewareCachingConfiguration<RequestBodyT, CacheT, CacheKeyT>
59where
60 CacheT: Clone,
61{
62 fn clone(&self) -> Self {
63 Self {
66 cache: self.cache.clone(),
67 cacheable_by_request: self.cacheable_by_request.clone(),
68 cacheable_by_response: self.cacheable_by_response.clone(),
69 cache_key: self.cache_key.clone(),
70 inner: self.inner.clone(),
71 }
72 }
73}
74
75#[derive(Clone)]
81pub struct MiddlewareEncodingConfiguration {
82 pub enabled_encodings_by_preference: Option<Vec<EncodingHeaderValue>>,
84
85 pub encodable_by_request: Option<EncodableHook>,
87
88 pub encodable_by_response: Option<EncodableHook>,
90
91 pub inner: EncodingConfiguration,
93}
94
95impl Default for MiddlewareEncodingConfiguration {
96 fn default() -> Self {
97 Self {
98 enabled_encodings_by_preference: Some(ENCODINGS_BY_PREFERENCE.into()),
99 encodable_by_request: None,
100 encodable_by_response: None,
101 inner: EncodingConfiguration { min_body_size: 0, encodable_by_default: true, keep_identity_encoding: true },
102 }
103 }
104}