diff options
author | Adam T. Carpenter <atc@53hor.net> | 2025-04-12 17:13:27 -0400 |
---|---|---|
committer | Adam T. Carpenter <atc@53hor.net> | 2025-04-12 17:13:27 -0400 |
commit | 7a56b66c6982441f957c1873a475ebcb4df98542 (patch) | |
tree | 0f2172df7f3c794df89ef2309dbce4fe3635c5cf /src/middleware/cache_control.rs | |
parent | 9bd21d3d07b74fdd0e761be72592fdff1d546861 (diff) | |
download | carpentertutoring-7a56b66c6982441f957c1873a475ebcb4df98542.tar.xz carpentertutoring-7a56b66c6982441f957c1873a475ebcb4df98542.zip |
feat: cache things from /assets
Diffstat (limited to 'src/middleware/cache_control.rs')
-rw-r--r-- | src/middleware/cache_control.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/middleware/cache_control.rs b/src/middleware/cache_control.rs new file mode 100644 index 0000000..30f31ca --- /dev/null +++ b/src/middleware/cache_control.rs @@ -0,0 +1,15 @@ +use axum::extract::Request; +use axum::http::header::{HeaderValue, CACHE_CONTROL}; +use axum::middleware::Next; +use axum::response::Response; + +pub async fn cache_static(mut request: Request, next: Next) -> Response { + let was_static = request.uri().path().starts_with("/assets"); + let mut response = next.run(request).await; + + if was_static { + response.headers_mut().insert(CACHE_CONTROL, HeaderValue::from_static("max-age=3600")); + } + + response +} |