index : static-web-server.git

ascending towards madness

author Jose Quintana <1700322+joseluisq@users.noreply.github.com> 2022-03-09 15:36:59.0 +00:00:00
committer GitHub <noreply@github.com> 2022-03-09 15:36:59.0 +00:00:00
commit
b2add23997dd5ef2995a69b55f604db0077d6ca7 [patch]
tree
34e77b02c3e292305db4aca268de69dc985ce281
parent
06cc3792299516f31e123462783392e2cb7b7f99
parent
62042057ef50d705a160326a8992b532268f7105
download
b2add23997dd5ef2995a69b55f604db0077d6ca7.tar.gz

Merge pull request #88 from csmith/cache-avif-jxl

feat: add AVIF and JPEG XL to one year cache-control list

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.