rocket::shield

Trait 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")
    }
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so 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"