kutil_http/cache/middleware/
hooks.rs1use {http::request::*, http::*, kutil_transcoding::*, std::sync::*};
2
3pub type CacheableHook = Arc<Box<dyn Fn(CacheableHookContext) -> bool + Send + Sync>>;
5
6pub type EncodableHook = Arc<Box<dyn Fn(EncodableHookContext) -> bool + Send + Sync>>;
8
9pub type CacheKeyHook<CacheKeyT, RequestBodyT> =
11 Arc<Box<dyn Fn(CacheKeyHookContext<CacheKeyT, RequestBodyT>) + Send + Sync>>;
12
13#[derive(Clone, Debug)]
19pub struct CacheableHookContext<'own> {
20 pub uri: &'own Uri,
22
23 pub headers: &'own HeaderMap,
25}
26
27impl<'own> CacheableHookContext<'own> {
28 pub fn new(uri: &'own Uri, headers: &'own HeaderMap) -> Self {
30 Self { uri, headers }
31 }
32}
33
34#[derive(Clone, Debug)]
40pub struct EncodableHookContext<'own> {
41 pub encoding: &'own Encoding,
43
44 pub uri: &'own Uri,
46
47 pub headers: &'own HeaderMap,
49}
50
51impl<'own> EncodableHookContext<'own> {
52 pub fn new(encoding: &'own Encoding, uri: &'own Uri, headers: &'own HeaderMap) -> Self {
54 Self { encoding, uri, headers }
55 }
56}
57
58#[derive(Debug)]
64pub struct CacheKeyHookContext<'own, CacheKeyT, RequestBodyT> {
65 pub cache_key: &'own mut CacheKeyT,
67
68 pub request: &'own Request<RequestBodyT>,
70}
71
72impl<'own, CacheKeyT, RequestBodyT> CacheKeyHookContext<'own, CacheKeyT, RequestBodyT> {
73 pub fn new(cache_key: &'own mut CacheKeyT, request: &'own Request<RequestBodyT>) -> Self {
75 Self { cache_key, request }
76 }
77}