pub struct SecurityHeaders { /* private fields */ }Expand description
A bundle of security headers applied as a single Tower Layer.
Use SecurityHeaders::recommended for a sensible default set, or build a
custom set with SecurityHeaders::new and add.
Call use_dev_headers(true) in development
to skip all headers (e.g. HSTS) that interfere with localhost workflows.
§Example
use axum::Router;
use axum_security::headers::{SecurityHeaders, XssProtection};
let headers = SecurityHeaders::recommended()
.add(XssProtection::ZERO);
let app = Router::<()>::new().layer(headers);Implementations§
Source§impl SecurityHeaders
impl SecurityHeaders
Sourcepub fn recommended() -> Self
pub fn recommended() -> Self
Create a SecurityHeaders set with sensible defaults.
Includes: Cross-Origin-Opener-Policy: same-origin,
Cross-Origin-Resource-Policy: same-origin, Origin-Agent-Cluster: ?1,
Referrer-Policy: no-referrer, Strict-Transport-Security: max-age=31536000; includeSubDomains,
X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN, X-XSS-Protection: 0.
Sourcepub fn use_dev_headers(self, dev_headers: bool) -> Self
pub fn use_dev_headers(self, dev_headers: bool) -> Self
When true, clears all headers so nothing is added to responses.
Use this in development to avoid HSTS and other headers that interfere
with localhost or plain HTTP.
Sourcepub fn add(self, header: impl IntoSecurityHeader) -> Self
pub fn add(self, header: impl IntoSecurityHeader) -> Self
Add a header, replacing any existing header with the same name.
Sourcepub fn try_add(self, header: impl IntoSecurityHeader) -> Self
pub fn try_add(self, header: impl IntoSecurityHeader) -> Self
Add a header only if no header with that name exists yet.
Trait Implementations§
Source§impl Clone for SecurityHeaders
impl Clone for SecurityHeaders
Source§fn clone(&self) -> SecurityHeaders
fn clone(&self) -> SecurityHeaders
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more