use axum::http::{HeaderValue, header};
use axum::response::Response;
pub const POLICY: &str = "script-src 'self'; worker-src 'self'; manifest-src 'self'; default-src 'self'; connect-src 'self'; img-src 'self' data: blob:; \
object-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'";
pub const LOGO_POLICY: &str = "default-src 'none'; sandbox; frame-ancestors 'none'";
pub const WORKER_POLICY: &str = "default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self'";
pub async fn on_html(mut response: Response) -> Response {
let is_html = response
.headers()
.get(header::CONTENT_TYPE)
.and_then(|t| t.to_str().ok())
.is_some_and(|t| t.trim_start().to_ascii_lowercase().starts_with("text/html"));
if is_html {
response
.headers_mut()
.insert(header::CONTENT_SECURITY_POLICY, HeaderValue::from_static(POLICY));
}
response
}