docspec_http/cache.rs
1//! Cache-Control middleware for all HTTP responses.
2
3use axum::http::{header::CACHE_CONTROL, HeaderValue};
4use tower_http::set_header::SetResponseHeaderLayer;
5
6use crate::format::CACHE_CONTROL_VALUE;
7
8/// Returns a middleware layer that adds [`CACHE_CONTROL_VALUE`] to every
9/// response, overriding any existing Cache-Control header.
10///
11/// This prevents intermediate proxies and clients from caching conversion results
12/// or health check responses.
13#[inline]
14pub fn cache_control_layer() -> SetResponseHeaderLayer<HeaderValue> {
15 SetResponseHeaderLayer::overriding(CACHE_CONTROL, HeaderValue::from_static(CACHE_CONTROL_VALUE))
16}