1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Like [`include_dir`](https://docs.rs/include_dir), but specialized for
//! serving a directory as a web application.
//!
//! ## Differences from `include_dir`
//!
//! - Only files are included. Directories are excluded.
//! - Paths must be valid UTF-8 without nul characters.
//! - Path lookup is optimized (using [`litemap`]).
//! - File metadata useful for HTTP caching are computed at build time.
//!
//! ## HTTP Caching Headers
//!
//! [`CWebFile`] fields provide values which can be used for HTTP cache-related
//! response headers:
//!
//! - `ETag` is the base32-encoded rapidhash of the file contents.
//! - `Last-Modified` is read from the filesystem metadata.
//! - `Cache-Control: immutable` can be set if the path starts with `assets/`.
//!
//! ### Immutable Assets
//!
//! The assumption that files under `assets/` should be immutable comes from
//! the default settings of [Vite](https://vite.dev/). Most modern web apps use
//! Vite as a bundler. Its default settings implement the "cache-busting"
//! pattern, meaning that static resources will be written to a subpath of
//! `assets/` and a hash will be appended to file names before the file
//! extension. This pattern makes it possible to cache entire static web
//! applications on the client web browser.
use CStr;
pub use include_cwebdir;
pub use litemap;
/// File data with HTTP cache-related metadata.
/// Map of paths to files.
pub type CWebBundle<'a> = LiteMap;