pub struct SecurityHeaders { /* private fields */ }Expand description
The security headers added to every reply web-net sends (pages, error pages, files, redirects), unless the handler set the same field itself.
The defaults are strict: a page may load scripts, styles, images, and fonts from its own origin only, may not be framed, and sends a short referrer to other origins. A site that needs more says so.
use web_net::SecurityHeaders;
let policy = SecurityHeaders::default()
.content_security_policy("default-src 'self'; img-src 'self' https://cdn.example; frame-ancestors 'none'")
.hsts(63_072_000, true);Implementations§
Source§impl SecurityHeaders
impl SecurityHeaders
Sourcepub fn none() -> Self
pub fn none() -> Self
No security headers at all (x-content-type-options: nosniff is
still sent: it has no cost and no downside).
Sourcepub fn content_security_policy(self, value: &str) -> Self
pub fn content_security_policy(self, value: &str) -> Self
Content-Security-Policy.
Sourcepub fn no_content_security_policy(self) -> Self
pub fn no_content_security_policy(self) -> Self
No Content-Security-Policy.
Sourcepub fn frame_options(self, value: &str) -> Self
pub fn frame_options(self, value: &str) -> Self
X-Frame-Options (DENY by default; SAMEORIGIN to allow the site’s
own frames).
Sourcepub fn referrer_policy(self, value: &str) -> Self
pub fn referrer_policy(self, value: &str) -> Self
Referrer-Policy.
Sourcepub fn permissions_policy(self, value: &str) -> Self
pub fn permissions_policy(self, value: &str) -> Self
Permissions-Policy.
Sourcepub fn opener_policy(self, value: &str) -> Self
pub fn opener_policy(self, value: &str) -> Self
Cross-Origin-Opener-Policy.
Trait Implementations§
Source§impl Clone for SecurityHeaders
impl Clone for SecurityHeaders
Source§impl Debug for SecurityHeaders
impl Debug for SecurityHeaders
Source§impl Default for SecurityHeaders
impl Default for SecurityHeaders
impl Eq for SecurityHeaders
Source§impl PartialEq for SecurityHeaders
impl PartialEq for SecurityHeaders
impl StructuralPartialEq for SecurityHeaders
Auto Trait Implementations§
impl Forget for SecurityHeaders
impl Freeze for SecurityHeaders
impl RefUnwindSafe for SecurityHeaders
impl Send for SecurityHeaders
impl Sync for SecurityHeaders
impl Unpin for SecurityHeaders
impl UnsafeUnpin for SecurityHeaders
impl UnwindSafe for SecurityHeaders
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