summaryrefslogtreecommitdiff
path: root/src/middleware/cache_control.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/middleware/cache_control.rs')
-rw-r--r--src/middleware/cache_control.rs15
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
+}