Skip to main content

trillium_caching_headers/
lib.rs

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