pub struct SecurityHeadersBuilder { /* private fields */ }Expand description
Builder for SecurityHeaders.
Provides a fluent interface for configuring security headers.
Implementations§
Source§impl SecurityHeadersBuilder
impl SecurityHeadersBuilder
Sourcepub fn content_security_policy(self, policy: ContentSecurityPolicy) -> Self
pub fn content_security_policy(self, policy: ContentSecurityPolicy) -> Self
Sets the Content-Security-Policy.
§Examples
use http_security_headers::{SecurityHeaders, ContentSecurityPolicy};
let csp = ContentSecurityPolicy::new()
.default_src(vec!["'self'"])
.script_src(vec!["'self'", "'unsafe-inline'"]);
let headers = SecurityHeaders::builder()
.content_security_policy(csp)
.build()
.unwrap();Sourcepub fn strict_transport_security(
self,
max_age: Duration,
include_subdomains: bool,
preload: bool,
) -> Self
pub fn strict_transport_security( self, max_age: Duration, include_subdomains: bool, preload: bool, ) -> Self
Sets the Strict-Transport-Security header.
§Arguments
max_age- Duration for the max-age directiveinclude_subdomains- Whether to include the includeSubDomains directivepreload- Whether to include the preload directive
§Examples
use http_security_headers::SecurityHeaders;
use std::time::Duration;
let headers = SecurityHeaders::builder()
.strict_transport_security(Duration::from_secs(31536000), true, false)
.build()
.unwrap();Sourcepub fn strict_transport_security_policy(
self,
policy: StrictTransportSecurity,
) -> Self
pub fn strict_transport_security_policy( self, policy: StrictTransportSecurity, ) -> Self
Sets the Strict-Transport-Security header with a custom policy.
Sourcepub fn x_frame_options_deny(self) -> Self
pub fn x_frame_options_deny(self) -> Self
Sets X-Frame-Options to DENY.
§Examples
use http_security_headers::SecurityHeaders;
let headers = SecurityHeaders::builder()
.x_frame_options_deny()
.build()
.unwrap();Sourcepub fn x_frame_options_sameorigin(self) -> Self
pub fn x_frame_options_sameorigin(self) -> Self
Sets X-Frame-Options to SAMEORIGIN.
§Examples
use http_security_headers::SecurityHeaders;
let headers = SecurityHeaders::builder()
.x_frame_options_sameorigin()
.build()
.unwrap();Sourcepub fn x_frame_options(self, policy: XFrameOptions) -> Self
pub fn x_frame_options(self, policy: XFrameOptions) -> Self
Sets the X-Frame-Options header with a custom value.
Sourcepub fn x_content_type_options_nosniff(self) -> Self
pub fn x_content_type_options_nosniff(self) -> Self
Enables X-Content-Type-Options: nosniff.
This is enabled by default in preset configurations.
§Examples
use http_security_headers::SecurityHeaders;
let headers = SecurityHeaders::builder()
.x_content_type_options_nosniff()
.build()
.unwrap();Sourcepub fn referrer_policy(self, policy: ReferrerPolicy) -> Self
pub fn referrer_policy(self, policy: ReferrerPolicy) -> Self
Sets the Referrer-Policy header.
Sourcepub fn referrer_policy_no_referrer(self) -> Self
pub fn referrer_policy_no_referrer(self) -> Self
Sets Referrer-Policy to no-referrer.
Sourcepub fn referrer_policy_strict_origin_when_cross_origin(self) -> Self
pub fn referrer_policy_strict_origin_when_cross_origin(self) -> Self
Sets Referrer-Policy to strict-origin-when-cross-origin.
Sourcepub fn cross_origin_opener_policy(self, policy: CrossOriginOpenerPolicy) -> Self
pub fn cross_origin_opener_policy(self, policy: CrossOriginOpenerPolicy) -> Self
Sets the Cross-Origin-Opener-Policy header.
Sourcepub fn cross_origin_embedder_policy(
self,
policy: CrossOriginEmbedderPolicy,
) -> Self
pub fn cross_origin_embedder_policy( self, policy: CrossOriginEmbedderPolicy, ) -> Self
Sets the Cross-Origin-Embedder-Policy header.
Sourcepub fn cross_origin_resource_policy(
self,
policy: CrossOriginResourcePolicy,
) -> Self
pub fn cross_origin_resource_policy( self, policy: CrossOriginResourcePolicy, ) -> Self
Sets the Cross-Origin-Resource-Policy header.
Sourcepub fn build(self) -> Result<SecurityHeaders>
pub fn build(self) -> Result<SecurityHeaders>
Trait Implementations§
Source§impl Debug for SecurityHeadersBuilder
impl Debug for SecurityHeadersBuilder
Source§impl Default for SecurityHeadersBuilder
impl Default for SecurityHeadersBuilder
Source§fn default() -> SecurityHeadersBuilder
fn default() -> SecurityHeadersBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SecurityHeadersBuilder
impl RefUnwindSafe for SecurityHeadersBuilder
impl Send for SecurityHeadersBuilder
impl Sync for SecurityHeadersBuilder
impl Unpin for SecurityHeadersBuilder
impl UnwindSafe for SecurityHeadersBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more