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

    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

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

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

Implementors