pub async fn security_headers_middleware(
__arg0: Extension<Arc<Vec<(HeaderName, HeaderValue)>>>,
request: Request,
next: Next,
) -> ResponseExpand description
Middleware to add security headers to all responses.
This middleware reads the pre-built headers from an Extension and applies
them to every response. It should be added as the outermost layer so headers
are applied to all routes.
§Example
ⓘ
use axum::{middleware, Router, Extension};
use tinycongress_api::http::security::{build_security_headers, security_headers_middleware};
use tinycongress_api::config::SecurityHeadersConfig;
let config = SecurityHeadersConfig::default();
let headers = build_security_headers(&config);
let app = Router::new()
// ... routes ...
.layer(middleware::from_fn(security_headers_middleware))
.layer(Extension(headers));