summaryrefslogtreecommitdiff
path: root/src/middleware/cache_control.rs
blob: 30f31ca56b5e86d7ac7267c8e2626c231b786352 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
}