Skip to main content

SecurityHeaders

Struct SecurityHeaders 

Source
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

Source

pub fn none() -> Self

No security headers at all (x-content-type-options: nosniff is still sent: it has no cost and no downside).

Source

pub fn content_security_policy(self, value: &str) -> Self

Content-Security-Policy.

Source

pub fn no_content_security_policy(self) -> Self

No Content-Security-Policy.

Source

pub fn frame_options(self, value: &str) -> Self

X-Frame-Options (DENY by default; SAMEORIGIN to allow the site’s own frames).

Source

pub fn referrer_policy(self, value: &str) -> Self

Referrer-Policy.

Source

pub fn permissions_policy(self, value: &str) -> Self

Permissions-Policy.

Source

pub fn opener_policy(self, value: &str) -> Self

Cross-Origin-Opener-Policy.

Source

pub fn hsts(self, max_age: u64, include_subdomains: bool) -> Self

Strict-Transport-Security, sent on HTTPS replies only and never to a development host. include_subdomains commits every subdomain to HTTPS too: set it only when they all have it.

Source

pub fn no_hsts(self) -> Self

No Strict-Transport-Security.

Trait Implementations§

Source§

impl Clone for SecurityHeaders

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SecurityHeaders

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SecurityHeaders

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for SecurityHeaders

Source§

impl PartialEq for SecurityHeaders

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SecurityHeaders

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.