trillium_caching_headers/
lib.rs

1/*!
2# Trillium handlers for etag and last-modified-since headers.
3
4This crate provides three handlers: [`Etag`], [`Modified`], and
5[`CachingHeaders`], as well as a [`CachingHeadersExt`] that extends
6[`trillium::Headers`] with some accessors.
7
8Unless you are sure that you _don't_ want either etag or last-modified
9behavior, please use the combined [`CachingHeaders`] handler.
10
11 */
12#![forbid(unsafe_code)]
13#![deny(
14    missing_copy_implementations,
15    rustdoc::missing_crate_level_docs,
16    missing_debug_implementations,
17    missing_docs,
18    nonstandard_style,
19    unused_qualifications
20)]
21
22mod etag;
23pub use crate::etag::Etag;
24pub use ::etag::EntityTag;
25
26mod modified;
27pub use modified::Modified;
28
29mod caching_conn_ext;
30pub use caching_conn_ext::CachingHeadersExt;
31
32mod cache_control;
33pub use cache_control::{cache_control, CacheControlDirective, CacheControlHeader};
34
35/**
36A combined handler that provides both [`Etag`] and [`Modified`]
37behavior.
38*/
39#[derive(Debug, Clone, Copy, Default)]
40pub struct CachingHeaders((Modified, Etag));
41trillium::delegate_handler!(CachingHeaders);
42
43impl CachingHeaders {
44    /// Constructs a new combination modified and etag handler
45    pub fn new() -> Self {
46        Self::default()
47    }
48}
49
50/// alias for [`CachingHeaders::new`]
51pub fn caching_headers() -> CachingHeaders {
52    CachingHeaders::new()
53}