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() -> PermissionsPolicy
pub const fn empty() -> PermissionsPolicy
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,
) -> PermissionsPolicy
pub fn with_directive( self, directive: PermissionsPolicyDirective, ) -> PermissionsPolicy
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 PermissionsPolicy
pub fn set_directive( &mut self, directive: PermissionsPolicyDirective, ) -> &mut PermissionsPolicy
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) -> PermissionsPolicy
pub fn with_deny_camera(self) -> PermissionsPolicy
Set camera=() (deny-all).
Sourcepub fn set_deny_camera(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_camera(&mut self) -> &mut PermissionsPolicy
Set camera=() (deny-all).
Sourcepub fn with_deny_microphone(self) -> PermissionsPolicy
pub fn with_deny_microphone(self) -> PermissionsPolicy
Set microphone=() (deny-all).
Sourcepub fn set_deny_microphone(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_microphone(&mut self) -> &mut PermissionsPolicy
Set microphone=() (deny-all).
Sourcepub fn with_deny_geolocation(self) -> PermissionsPolicy
pub fn with_deny_geolocation(self) -> PermissionsPolicy
Set geolocation=() (deny-all).
Sourcepub fn set_deny_geolocation(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_geolocation(&mut self) -> &mut PermissionsPolicy
Set geolocation=() (deny-all).
Sourcepub fn with_deny_payment(self) -> PermissionsPolicy
pub fn with_deny_payment(self) -> PermissionsPolicy
Set payment=() (deny-all).
Sourcepub fn set_deny_payment(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_payment(&mut self) -> &mut PermissionsPolicy
Set payment=() (deny-all).
Sourcepub fn with_deny_usb(self) -> PermissionsPolicy
pub fn with_deny_usb(self) -> PermissionsPolicy
Set usb=() (deny-all).
Sourcepub fn set_deny_usb(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_usb(&mut self) -> &mut PermissionsPolicy
Set usb=() (deny-all).
Sourcepub fn with_deny_interest_cohort(self) -> PermissionsPolicy
pub fn with_deny_interest_cohort(self) -> PermissionsPolicy
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 PermissionsPolicy
pub fn set_deny_interest_cohort(&mut self) -> &mut PermissionsPolicy
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) -> PermissionsPolicy
pub fn with_deny_browsing_topics(self) -> PermissionsPolicy
Set browsing-topics=() (deny-all). Opts the site out of
the Topics API (Privacy Sandbox).
Sourcepub fn set_deny_browsing_topics(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_browsing_topics(&mut self) -> &mut PermissionsPolicy
Set browsing-topics=() (deny-all). Opts the site out of
the Topics API (Privacy Sandbox).
Sourcepub fn with_deny_attribution_reporting(self) -> PermissionsPolicy
pub fn with_deny_attribution_reporting(self) -> PermissionsPolicy
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 PermissionsPolicy
pub fn set_deny_attribution_reporting(&mut self) -> &mut PermissionsPolicy
Set attribution-reporting=() (deny-all). Opts the site
out of the Attribution Reporting API (Privacy Sandbox).
Sourcepub fn with_deny_accelerometer(self) -> PermissionsPolicy
pub fn with_deny_accelerometer(self) -> PermissionsPolicy
Set accelerometer=() (deny-all).
Sourcepub fn set_deny_accelerometer(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_accelerometer(&mut self) -> &mut PermissionsPolicy
Set accelerometer=() (deny-all).
Sourcepub fn with_deny_ambient_light_sensor(self) -> PermissionsPolicy
pub fn with_deny_ambient_light_sensor(self) -> PermissionsPolicy
Set ambient-light-sensor=() (deny-all).
Sourcepub fn set_deny_ambient_light_sensor(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_ambient_light_sensor(&mut self) -> &mut PermissionsPolicy
Set ambient-light-sensor=() (deny-all).
Sourcepub fn with_deny_autoplay(self) -> PermissionsPolicy
pub fn with_deny_autoplay(self) -> PermissionsPolicy
Set autoplay=() (deny-all).
Sourcepub fn set_deny_autoplay(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_autoplay(&mut self) -> &mut PermissionsPolicy
Set autoplay=() (deny-all).
Sourcepub fn with_deny_battery(self) -> PermissionsPolicy
pub fn with_deny_battery(self) -> PermissionsPolicy
Set battery=() (deny-all).
Sourcepub fn set_deny_battery(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_battery(&mut self) -> &mut PermissionsPolicy
Set battery=() (deny-all).
Sourcepub fn with_deny_bluetooth(self) -> PermissionsPolicy
pub fn with_deny_bluetooth(self) -> PermissionsPolicy
Set bluetooth=() (deny-all).
Sourcepub fn set_deny_bluetooth(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_bluetooth(&mut self) -> &mut PermissionsPolicy
Set bluetooth=() (deny-all).
Sourcepub fn with_deny_display_capture(self) -> PermissionsPolicy
pub fn with_deny_display_capture(self) -> PermissionsPolicy
Set display-capture=() (deny-all).
Sourcepub fn set_deny_display_capture(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_display_capture(&mut self) -> &mut PermissionsPolicy
Set display-capture=() (deny-all).
Sourcepub fn with_deny_encrypted_media(self) -> PermissionsPolicy
pub fn with_deny_encrypted_media(self) -> PermissionsPolicy
Set encrypted-media=() (deny-all).
Sourcepub fn set_deny_encrypted_media(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_encrypted_media(&mut self) -> &mut PermissionsPolicy
Set encrypted-media=() (deny-all).
Sourcepub fn with_deny_fullscreen(self) -> PermissionsPolicy
pub fn with_deny_fullscreen(self) -> PermissionsPolicy
Set fullscreen=() (deny-all).
Sourcepub fn set_deny_fullscreen(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_fullscreen(&mut self) -> &mut PermissionsPolicy
Set fullscreen=() (deny-all).
Sourcepub fn with_deny_gyroscope(self) -> PermissionsPolicy
pub fn with_deny_gyroscope(self) -> PermissionsPolicy
Set gyroscope=() (deny-all).
Sourcepub fn set_deny_gyroscope(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_gyroscope(&mut self) -> &mut PermissionsPolicy
Set gyroscope=() (deny-all).
Sourcepub fn with_deny_idle_detection(self) -> PermissionsPolicy
pub fn with_deny_idle_detection(self) -> PermissionsPolicy
Set idle-detection=() (deny-all).
Sourcepub fn set_deny_idle_detection(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_idle_detection(&mut self) -> &mut PermissionsPolicy
Set idle-detection=() (deny-all).
Sourcepub fn with_deny_magnetometer(self) -> PermissionsPolicy
pub fn with_deny_magnetometer(self) -> PermissionsPolicy
Set magnetometer=() (deny-all).
Sourcepub fn set_deny_magnetometer(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_magnetometer(&mut self) -> &mut PermissionsPolicy
Set magnetometer=() (deny-all).
Sourcepub fn with_deny_midi(self) -> PermissionsPolicy
pub fn with_deny_midi(self) -> PermissionsPolicy
Set midi=() (deny-all).
Sourcepub fn set_deny_midi(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_midi(&mut self) -> &mut PermissionsPolicy
Set midi=() (deny-all).
Sourcepub fn with_deny_picture_in_picture(self) -> PermissionsPolicy
pub fn with_deny_picture_in_picture(self) -> PermissionsPolicy
Set picture-in-picture=() (deny-all).
Sourcepub fn set_deny_picture_in_picture(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_picture_in_picture(&mut self) -> &mut PermissionsPolicy
Set picture-in-picture=() (deny-all).
Sourcepub fn with_deny_publickey_credentials_get(self) -> PermissionsPolicy
pub fn with_deny_publickey_credentials_get(self) -> PermissionsPolicy
Set publickey-credentials-get=() (deny-all).
Sourcepub fn set_deny_publickey_credentials_get(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_publickey_credentials_get(&mut self) -> &mut PermissionsPolicy
Set publickey-credentials-get=() (deny-all).
Sourcepub fn with_deny_screen_wake_lock(self) -> PermissionsPolicy
pub fn with_deny_screen_wake_lock(self) -> PermissionsPolicy
Set screen-wake-lock=() (deny-all).
Sourcepub fn set_deny_screen_wake_lock(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_screen_wake_lock(&mut self) -> &mut PermissionsPolicy
Set screen-wake-lock=() (deny-all).
Sourcepub fn with_deny_sync_xhr(self) -> PermissionsPolicy
pub fn with_deny_sync_xhr(self) -> PermissionsPolicy
Set sync-xhr=() (deny-all).
Sourcepub fn set_deny_sync_xhr(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_sync_xhr(&mut self) -> &mut PermissionsPolicy
Set sync-xhr=() (deny-all).
Set web-share=() (deny-all).
Set web-share=() (deny-all).
Sourcepub fn with_deny_xr_spatial_tracking(self) -> PermissionsPolicy
pub fn with_deny_xr_spatial_tracking(self) -> PermissionsPolicy
Set xr-spatial-tracking=() (deny-all).
Sourcepub fn set_deny_xr_spatial_tracking(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_xr_spatial_tracking(&mut self) -> &mut PermissionsPolicy
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>(values: &mut I) -> Result<PermissionsPolicy, Error>where
I: Iterator<Item = &'i HeaderValue>,
fn decode<'i, I>(values: &mut I) -> Result<PermissionsPolicy, Error>where
I: Iterator<Item = &'i HeaderValue>,
HeaderValues.Source§impl HeaderEncode for PermissionsPolicy
impl HeaderEncode for PermissionsPolicy
Source§fn encode<E>(&self, values: &mut E)where
E: Extend<HeaderValue>,
fn encode<E>(&self, values: &mut E)where
E: Extend<HeaderValue>,
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<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
Source§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.