Trait rocket::shield::Policy

source ·
pub trait Policy: Default + Send + Sync + 'static {
    const NAME: &'static str;

    // Required method
    fn header(&self) -> Header<'static>;
}
Expand description

Trait implemented by security and privacy policy headers.

Types that implement this trait can be enable()d and disable()d on instances of Shield.

Required Associated Constants§

source

const NAME: &'static str

The actual name of the HTTP header.

This name must uniquely identify the header as it is used to determine whether two implementations of Policy are for the same header. Use the real HTTP header’s name.

§Example
use rocket::shield::Policy;

#[derive(Default)]
struct MyPolicy;

impl Policy for MyPolicy {
    const NAME: &'static str = "X-My-Policy";
}

Required Methods§

source

fn header(&self) -> Header<'static>

Returns the Header to attach to all outgoing responses.

§Example
use rocket::http::Header;
use rocket::shield::Policy;

#[derive(Default)]
struct MyPolicy;

impl Policy for MyPolicy {
    fn header(&self) -> Header<'static> {
        Header::new(Self::NAME, "value-to-enable")
    }
}

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Policy for ExpectCt

source§

const NAME: &'static str = "Expect-CT"

source§

impl Policy for Frame

source§

const NAME: &'static str = "X-Frame-Options"

source§

impl Policy for Hsts

source§

const NAME: &'static str = "Strict-Transport-Security"

source§

impl Policy for NoSniff

source§

const NAME: &'static str = "X-Content-Type-Options"

source§

impl Policy for Prefetch

source§

const NAME: &'static str = "X-DNS-Prefetch-Control"

source§

impl Policy for Referrer

source§

const NAME: &'static str = "Referrer-Policy"

source§

impl Policy for XssFilter

source§

const NAME: &'static str = "X-XSS-Protection"

source§

impl Policy for Permission

source§

const NAME: &'static str = "Permissions-Policy"