index : static-web-server.git

ascending towards madness

author Chris Smith <chris@chameth.com> 2022-03-09 14:22:29.0 +00:00:00
committer Chris Smith <chris@chameth.com> 2022-03-09 14:39:14.0 +00:00:00
commit
62042057ef50d705a160326a8992b532268f7105 [patch]
tree
34e77b02c3e292305db4aca268de69dc985ce281
parent
06cc3792299516f31e123462783392e2cb7b7f99
download
62042057ef50d705a160326a8992b532268f7105.tar.gz

feat: add avif and JPEG XL to cache-control list.

These are two 'next-gen' image formats, which should be cached
for the same length of time as jpegs/pngs/etc.

Diff

 docs/content/features/cache-control-headers.md | 2 +-
 src/control_headers.rs                         | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/docs/content/features/cache-control-headers.md b/docs/content/features/cache-control-headers.md
index 28f5be5..c063963 100644
--- a/docs/content/features/cache-control-headers.md
+++ b/docs/content/features/cache-control-headers.md
@@ -28,7 +28,7 @@ atom, json, rss, xml
A `max-age` of *one year* is applied only to the following file types.

```txt
bmp, bz2, css, doc, gif, gz, htc, ico, jpeg, jpg, js, map, mjs, mp3, mp4, ogg, ogv, pdf, png, rar, rtf, tar, tgz, wav, weba, webm, webp, woff, woff2, zip
avif, bmp, bz2, css, doc, gif, gz, htc, ico, jpeg, jpg, js, jxl, map, mjs, mp3, mp4, ogg, ogv, pdf, png, rar, rtf, tar, tgz, wav, weba, webm, webp, woff, woff2, zip
```

Below an example of how to enable the feature.
diff --git a/src/control_headers.rs b/src/control_headers.rs
index 558a6bf..aecc904 100644
--- a/src/control_headers.rs
+++ b/src/control_headers.rs
@@ -6,10 +6,10 @@ use headers::{CacheControl, HeaderMapExt};
use hyper::{Body, Response};

const CACHE_EXT_ONE_HOUR: [&str; 4] = ["atom", "json", "rss", "xml"];
const CACHE_EXT_ONE_YEAR: [&str; 30] = [
    "bmp", "bz2", "css", "doc", "gif", "gz", "htc", "ico", "jpeg", "jpg", "js", "map", "mjs",
    "mp3", "mp4", "ogg", "ogv", "pdf", "png", "rar", "rtf", "tar", "tgz", "wav", "weba", "webm",
    "webp", "woff", "woff2", "zip",
const CACHE_EXT_ONE_YEAR: [&str; 32] = [
    "avif", "bmp", "bz2", "css", "doc", "gif", "gz", "htc", "ico", "jpeg", "jpg", "js", "jxl",
    "map", "mjs", "mp3", "mp4", "ogg", "ogv", "pdf", "png", "rar", "rtf", "tar", "tgz", "wav",
    "weba", "webm", "webp", "woff", "woff2", "zip",
];

/// It appends a `Cache-Control` header to a response if that one is part of a set of file types.