pub struct PermissionsPolicy { /* private fields */ }Expand description
Permissions-Policy response header.
Adding a directive that already exists in the policy replaces its allow-list in place (preserving declared order). The user agent would treat the second occurrence as the winner per RFC 8941 structured-fields anyway, so we collapse to the caller-most-recent value.
§Examples
Deny the common ambient-capability features:
use rama_http_headers::PermissionsPolicy;
let pp = PermissionsPolicy::empty()
.with_deny_camera()
.with_deny_microphone()
.with_deny_geolocation()
.with_deny_payment()
.with_deny_usb()
.with_deny_interest_cohort();
let rendered = pp.to_string();
assert!(rendered.contains("camera=()"));
assert!(rendered.contains("interest-cohort=()"));Drop down to the generic surface for an allow-list or for a proposed/draft feature that isn’t yet modelled:
use rama_http_headers::{
PermissionsPolicy, PermissionsPolicyDirective, PermissionsPolicyDirectiveName,
AllowlistSource,
};
let pp = PermissionsPolicy::empty()
.with_directive(PermissionsPolicyDirective::allow(
PermissionsPolicyDirectiveName::Camera,
AllowlistSource::SelfOrigin,
))
.with_directive(PermissionsPolicyDirective::deny(
// Unknown / vendor / draft feature names land in the
// auto-generated `Unknown` variant via `From<&str>`.
PermissionsPolicyDirectiveName::from("x-vendor-experimental"),
));
assert_eq!(pp.to_string(), "camera=(self), x-vendor-experimental=()");Implementations§
Source§impl PermissionsPolicy
impl PermissionsPolicy
Sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Empty policy. Build from this when adding directives one at a time.
Sourcepub fn directives(
&self,
) -> impl Iterator<Item = &PermissionsPolicyDirective> + '_
pub fn directives( &self, ) -> impl Iterator<Item = &PermissionsPolicyDirective> + '_
Iterate the policy’s directives in encoding order.
Sourcepub fn with_directive(self, directive: PermissionsPolicyDirective) -> Self
pub fn with_directive(self, directive: PermissionsPolicyDirective) -> Self
Generic escape hatch: append or replace a directive by name. If a directive with the same name exists, its allow-list is overwritten in place (order preserved); otherwise it’s appended.
The macro generates the &mut self sibling
set_directive.
Sourcepub fn set_directive(
&mut self,
directive: PermissionsPolicyDirective,
) -> &mut Self
pub fn set_directive( &mut self, directive: PermissionsPolicyDirective, ) -> &mut Self
Generic escape hatch: append or replace a directive by name. If a directive with the same name exists, its allow-list is overwritten in place (order preserved); otherwise it’s appended.
The macro generates the &mut self sibling
set_directive.
Sourcepub fn with_deny_camera(self) -> Self
pub fn with_deny_camera(self) -> Self
Set camera=() (deny-all).
Sourcepub fn set_deny_camera(&mut self) -> &mut Self
pub fn set_deny_camera(&mut self) -> &mut Self
Set camera=() (deny-all).
Sourcepub fn with_deny_microphone(self) -> Self
pub fn with_deny_microphone(self) -> Self
Set microphone=() (deny-all).
Sourcepub fn set_deny_microphone(&mut self) -> &mut Self
pub fn set_deny_microphone(&mut self) -> &mut Self
Set microphone=() (deny-all).
Sourcepub fn with_deny_geolocation(self) -> Self
pub fn with_deny_geolocation(self) -> Self
Set geolocation=() (deny-all).
Sourcepub fn set_deny_geolocation(&mut self) -> &mut Self
pub fn set_deny_geolocation(&mut self) -> &mut Self
Set geolocation=() (deny-all).
Sourcepub fn with_deny_payment(self) -> Self
pub fn with_deny_payment(self) -> Self
Set payment=() (deny-all).
Sourcepub fn set_deny_payment(&mut self) -> &mut Self
pub fn set_deny_payment(&mut self) -> &mut Self
Set payment=() (deny-all).
Sourcepub fn with_deny_usb(self) -> Self
pub fn with_deny_usb(self) -> Self
Set usb=() (deny-all).
Sourcepub fn set_deny_usb(&mut self) -> &mut Self
pub fn set_deny_usb(&mut self) -> &mut Self
Set usb=() (deny-all).
Sourcepub fn with_deny_interest_cohort(self) -> Self
pub fn with_deny_interest_cohort(self) -> Self
Set interest-cohort=() (deny-all). Opts the site out of
the deprecated FLoC experiment. Pair with
deny_browsing_topics
to also block Topics API, FLoC’s shipped successor.
Sourcepub fn set_deny_interest_cohort(&mut self) -> &mut Self
pub fn set_deny_interest_cohort(&mut self) -> &mut Self
Set interest-cohort=() (deny-all). Opts the site out of
the deprecated FLoC experiment. Pair with
deny_browsing_topics
to also block Topics API, FLoC’s shipped successor.
Sourcepub fn with_deny_browsing_topics(self) -> Self
pub fn with_deny_browsing_topics(self) -> Self
Set browsing-topics=() (deny-all). Opts the site out of
the Topics API (Privacy Sandbox).
Sourcepub fn set_deny_browsing_topics(&mut self) -> &mut Self
pub fn set_deny_browsing_topics(&mut self) -> &mut Self
Set browsing-topics=() (deny-all). Opts the site out of
the Topics API (Privacy Sandbox).
Sourcepub fn with_deny_attribution_reporting(self) -> Self
pub fn with_deny_attribution_reporting(self) -> Self
Set attribution-reporting=() (deny-all). Opts the site
out of the Attribution Reporting API (Privacy Sandbox).
Sourcepub fn set_deny_attribution_reporting(&mut self) -> &mut Self
pub fn set_deny_attribution_reporting(&mut self) -> &mut Self
Set attribution-reporting=() (deny-all). Opts the site
out of the Attribution Reporting API (Privacy Sandbox).
Sourcepub fn with_deny_accelerometer(self) -> Self
pub fn with_deny_accelerometer(self) -> Self
Set accelerometer=() (deny-all).
Sourcepub fn set_deny_accelerometer(&mut self) -> &mut Self
pub fn set_deny_accelerometer(&mut self) -> &mut Self
Set accelerometer=() (deny-all).
Sourcepub fn with_deny_ambient_light_sensor(self) -> Self
pub fn with_deny_ambient_light_sensor(self) -> Self
Set ambient-light-sensor=() (deny-all).
Sourcepub fn set_deny_ambient_light_sensor(&mut self) -> &mut Self
pub fn set_deny_ambient_light_sensor(&mut self) -> &mut Self
Set ambient-light-sensor=() (deny-all).
Sourcepub fn with_deny_autoplay(self) -> Self
pub fn with_deny_autoplay(self) -> Self
Set autoplay=() (deny-all).
Sourcepub fn set_deny_autoplay(&mut self) -> &mut Self
pub fn set_deny_autoplay(&mut self) -> &mut Self
Set autoplay=() (deny-all).
Sourcepub fn with_deny_battery(self) -> Self
pub fn with_deny_battery(self) -> Self
Set battery=() (deny-all).
Sourcepub fn set_deny_battery(&mut self) -> &mut Self
pub fn set_deny_battery(&mut self) -> &mut Self
Set battery=() (deny-all).
Sourcepub fn with_deny_bluetooth(self) -> Self
pub fn with_deny_bluetooth(self) -> Self
Set bluetooth=() (deny-all).
Sourcepub fn set_deny_bluetooth(&mut self) -> &mut Self
pub fn set_deny_bluetooth(&mut self) -> &mut Self
Set bluetooth=() (deny-all).
Sourcepub fn with_deny_display_capture(self) -> Self
pub fn with_deny_display_capture(self) -> Self
Set display-capture=() (deny-all).
Sourcepub fn set_deny_display_capture(&mut self) -> &mut Self
pub fn set_deny_display_capture(&mut self) -> &mut Self
Set display-capture=() (deny-all).
Sourcepub fn with_deny_encrypted_media(self) -> Self
pub fn with_deny_encrypted_media(self) -> Self
Set encrypted-media=() (deny-all).
Sourcepub fn set_deny_encrypted_media(&mut self) -> &mut Self
pub fn set_deny_encrypted_media(&mut self) -> &mut Self
Set encrypted-media=() (deny-all).
Sourcepub fn with_deny_fullscreen(self) -> Self
pub fn with_deny_fullscreen(self) -> Self
Set fullscreen=() (deny-all).
Sourcepub fn set_deny_fullscreen(&mut self) -> &mut Self
pub fn set_deny_fullscreen(&mut self) -> &mut Self
Set fullscreen=() (deny-all).
Sourcepub fn with_deny_gyroscope(self) -> Self
pub fn with_deny_gyroscope(self) -> Self
Set gyroscope=() (deny-all).
Sourcepub fn set_deny_gyroscope(&mut self) -> &mut Self
pub fn set_deny_gyroscope(&mut self) -> &mut Self
Set gyroscope=() (deny-all).
Sourcepub fn with_deny_idle_detection(self) -> Self
pub fn with_deny_idle_detection(self) -> Self
Set idle-detection=() (deny-all).
Sourcepub fn set_deny_idle_detection(&mut self) -> &mut Self
pub fn set_deny_idle_detection(&mut self) -> &mut Self
Set idle-detection=() (deny-all).
Sourcepub fn with_deny_magnetometer(self) -> Self
pub fn with_deny_magnetometer(self) -> Self
Set magnetometer=() (deny-all).
Sourcepub fn set_deny_magnetometer(&mut self) -> &mut Self
pub fn set_deny_magnetometer(&mut self) -> &mut Self
Set magnetometer=() (deny-all).
Sourcepub fn with_deny_midi(self) -> Self
pub fn with_deny_midi(self) -> Self
Set midi=() (deny-all).
Sourcepub fn set_deny_midi(&mut self) -> &mut Self
pub fn set_deny_midi(&mut self) -> &mut Self
Set midi=() (deny-all).
Sourcepub fn with_deny_picture_in_picture(self) -> Self
pub fn with_deny_picture_in_picture(self) -> Self
Set picture-in-picture=() (deny-all).
Sourcepub fn set_deny_picture_in_picture(&mut self) -> &mut Self
pub fn set_deny_picture_in_picture(&mut self) -> &mut Self
Set picture-in-picture=() (deny-all).
Sourcepub fn with_deny_publickey_credentials_get(self) -> Self
pub fn with_deny_publickey_credentials_get(self) -> Self
Set publickey-credentials-get=() (deny-all).
Sourcepub fn set_deny_publickey_credentials_get(&mut self) -> &mut Self
pub fn set_deny_publickey_credentials_get(&mut self) -> &mut Self
Set publickey-credentials-get=() (deny-all).
Sourcepub fn with_deny_screen_wake_lock(self) -> Self
pub fn with_deny_screen_wake_lock(self) -> Self
Set screen-wake-lock=() (deny-all).
Sourcepub fn set_deny_screen_wake_lock(&mut self) -> &mut Self
pub fn set_deny_screen_wake_lock(&mut self) -> &mut Self
Set screen-wake-lock=() (deny-all).
Sourcepub fn with_deny_sync_xhr(self) -> Self
pub fn with_deny_sync_xhr(self) -> Self
Set sync-xhr=() (deny-all).
Sourcepub fn set_deny_sync_xhr(&mut self) -> &mut Self
pub fn set_deny_sync_xhr(&mut self) -> &mut Self
Set sync-xhr=() (deny-all).
Set web-share=() (deny-all).
Set web-share=() (deny-all).
Sourcepub fn with_deny_xr_spatial_tracking(self) -> Self
pub fn with_deny_xr_spatial_tracking(self) -> Self
Set xr-spatial-tracking=() (deny-all).
Sourcepub fn set_deny_xr_spatial_tracking(&mut self) -> &mut Self
pub fn set_deny_xr_spatial_tracking(&mut self) -> &mut Self
Set xr-spatial-tracking=() (deny-all).
Trait Implementations§
Source§impl Clone for PermissionsPolicy
impl Clone for PermissionsPolicy
Source§fn clone(&self) -> PermissionsPolicy
fn clone(&self) -> PermissionsPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PermissionsPolicy
impl Debug for PermissionsPolicy
Source§impl Default for PermissionsPolicy
impl Default for PermissionsPolicy
Source§fn default() -> PermissionsPolicy
fn default() -> PermissionsPolicy
Source§impl Display for PermissionsPolicy
impl Display for PermissionsPolicy
impl Eq for PermissionsPolicy
Source§impl HeaderDecode for PermissionsPolicy
impl HeaderDecode for PermissionsPolicy
Source§fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(
values: &mut I,
) -> Result<Self, Error>
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>( values: &mut I, ) -> Result<Self, Error>
HeaderValues.Source§impl HeaderEncode for PermissionsPolicy
impl HeaderEncode for PermissionsPolicy
Source§fn encode<E: Extend<HeaderValue>>(&self, values: &mut E)
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E)
HeaderValue, and add it to a container
which has HeaderValue type as each element. Read moreSource§fn encode_to_value(&self) -> Option<HeaderValue>
fn encode_to_value(&self) -> Option<HeaderValue>
HeaderValue. Read moreSource§impl PartialEq for PermissionsPolicy
impl PartialEq for PermissionsPolicy
Source§fn eq(&self, other: &PermissionsPolicy) -> bool
fn eq(&self, other: &PermissionsPolicy) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for PermissionsPolicy
Source§impl TypedHeader for PermissionsPolicy
impl TypedHeader for PermissionsPolicy
Source§fn name() -> &'static HeaderName
fn name() -> &'static HeaderName
Auto Trait Implementations§
impl Freeze for PermissionsPolicy
impl RefUnwindSafe for PermissionsPolicy
impl Send for PermissionsPolicy
impl Sync for PermissionsPolicy
impl Unpin for PermissionsPolicy
impl UnsafeUnpin for PermissionsPolicy
impl UnwindSafe for PermissionsPolicy
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more