kanidmd_core/https/middleware/
hsts_header.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use axum::{
    body::Body,
    http::{header, HeaderValue, Request},
    middleware::Next,
    response::Response,
};

const HSTS_HEADER: &str = "max-age=86400";

pub async fn strict_transport_security_layer(request: Request<Body>, next: Next) -> Response {
    // wait for the middleware to come back
    let mut response = next.run(request).await;

    // add the header
    response.headers_mut().insert(
        header::STRICT_TRANSPORT_SECURITY,
        HeaderValue::from_static(HSTS_HEADER),
    );

    response
}