tower_http_cache_plus/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<'this> {
20 pub uri: &'this Uri,
22
23 pub headers: &'this HeaderMap,
25}
26
27impl<'this> CacheableHookContext<'this> {
28 pub fn new(uri: &'this Uri, headers: &'this HeaderMap) -> Self {
30 Self { uri, headers }
31 }
32}
33
34#[derive(Clone, Debug)]
40pub struct EncodableHookContext<'this> {
41 pub encoding: &'this Encoding,
43
44 pub uri: &'this Uri,
46
47 pub headers: &'this HeaderMap,
49}
50
51impl<'this> EncodableHookContext<'this> {
52 pub fn new(encoding: &'this Encoding, uri: &'this Uri, headers: &'this HeaderMap) -> Self {
54 Self {
55 encoding,
56 uri,
57 headers,
58 }
59 }
60}
61
62#[derive(Debug)]
68pub struct CacheKeyHookContext<'this, CacheKeyT, RequestBodyT> {
69 pub cache_key: &'this mut CacheKeyT,
71
72 pub request: &'this Request<RequestBodyT>,
74}
75
76impl<'this, CacheKeyT, RequestBodyT> CacheKeyHookContext<'this, CacheKeyT, RequestBodyT> {
77 pub fn new(cache_key: &'this mut CacheKeyT, request: &'this Request<RequestBodyT>) -> Self {
79 Self { cache_key, request }
80 }
81}