kanidmd_core/https/middleware/
hsts_header.rs

1use axum::{
2    body::Body,
3    http::{header, HeaderValue, Request},
4    middleware::Next,
5    response::Response,
6};
7
8const HSTS_HEADER: &str = "max-age=86400";
9
10pub async fn strict_transport_security_layer(request: Request<Body>, next: Next) -> Response {
11    // wait for the middleware to come back
12    let mut response = next.run(request).await;
13
14    // add the header
15    response.headers_mut().insert(
16        header::STRICT_TRANSPORT_SECURITY,
17        HeaderValue::from_static(HSTS_HEADER),
18    );
19
20    response
21}