Struct PermissionsPolicy
pub struct PermissionsPolicy { /* private fields */ }http only.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§
§impl PermissionsPolicy
impl PermissionsPolicy
pub const fn empty() -> PermissionsPolicy
pub const fn empty() -> PermissionsPolicy
Empty policy. Build from this when adding directives one at a time.
pub fn directives(&self) -> impl Iterator<Item = &PermissionsPolicyDirective>
pub fn directives(&self) -> impl Iterator<Item = &PermissionsPolicyDirective>
Iterate the policy’s directives in encoding order.
pub 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.
pub 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.
pub fn with_deny_camera(self) -> PermissionsPolicy
pub fn with_deny_camera(self) -> PermissionsPolicy
Set camera=() (deny-all).
pub fn set_deny_camera(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_camera(&mut self) -> &mut PermissionsPolicy
Set camera=() (deny-all).
pub fn with_deny_microphone(self) -> PermissionsPolicy
pub fn with_deny_microphone(self) -> PermissionsPolicy
Set microphone=() (deny-all).
pub fn set_deny_microphone(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_microphone(&mut self) -> &mut PermissionsPolicy
Set microphone=() (deny-all).
pub fn with_deny_geolocation(self) -> PermissionsPolicy
pub fn with_deny_geolocation(self) -> PermissionsPolicy
Set geolocation=() (deny-all).
pub fn set_deny_geolocation(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_geolocation(&mut self) -> &mut PermissionsPolicy
Set geolocation=() (deny-all).
pub fn with_deny_payment(self) -> PermissionsPolicy
pub fn with_deny_payment(self) -> PermissionsPolicy
Set payment=() (deny-all).
pub fn set_deny_payment(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_payment(&mut self) -> &mut PermissionsPolicy
Set payment=() (deny-all).
pub fn with_deny_usb(self) -> PermissionsPolicy
pub fn with_deny_usb(self) -> PermissionsPolicy
Set usb=() (deny-all).
pub fn set_deny_usb(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_usb(&mut self) -> &mut PermissionsPolicy
Set usb=() (deny-all).
pub 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.
pub 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.
pub 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).
pub 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).
pub 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).
pub 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).
pub fn with_deny_accelerometer(self) -> PermissionsPolicy
pub fn with_deny_accelerometer(self) -> PermissionsPolicy
Set accelerometer=() (deny-all).
pub fn set_deny_accelerometer(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_accelerometer(&mut self) -> &mut PermissionsPolicy
Set accelerometer=() (deny-all).
pub fn with_deny_ambient_light_sensor(self) -> PermissionsPolicy
pub fn with_deny_ambient_light_sensor(self) -> PermissionsPolicy
Set ambient-light-sensor=() (deny-all).
pub 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).
pub fn with_deny_autoplay(self) -> PermissionsPolicy
pub fn with_deny_autoplay(self) -> PermissionsPolicy
Set autoplay=() (deny-all).
pub fn set_deny_autoplay(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_autoplay(&mut self) -> &mut PermissionsPolicy
Set autoplay=() (deny-all).
pub fn with_deny_battery(self) -> PermissionsPolicy
pub fn with_deny_battery(self) -> PermissionsPolicy
Set battery=() (deny-all).
pub fn set_deny_battery(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_battery(&mut self) -> &mut PermissionsPolicy
Set battery=() (deny-all).
pub fn with_deny_bluetooth(self) -> PermissionsPolicy
pub fn with_deny_bluetooth(self) -> PermissionsPolicy
Set bluetooth=() (deny-all).
pub fn set_deny_bluetooth(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_bluetooth(&mut self) -> &mut PermissionsPolicy
Set bluetooth=() (deny-all).
pub fn with_deny_display_capture(self) -> PermissionsPolicy
pub fn with_deny_display_capture(self) -> PermissionsPolicy
Set display-capture=() (deny-all).
pub fn set_deny_display_capture(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_display_capture(&mut self) -> &mut PermissionsPolicy
Set display-capture=() (deny-all).
pub fn with_deny_encrypted_media(self) -> PermissionsPolicy
pub fn with_deny_encrypted_media(self) -> PermissionsPolicy
Set encrypted-media=() (deny-all).
pub fn set_deny_encrypted_media(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_encrypted_media(&mut self) -> &mut PermissionsPolicy
Set encrypted-media=() (deny-all).
pub fn with_deny_fullscreen(self) -> PermissionsPolicy
pub fn with_deny_fullscreen(self) -> PermissionsPolicy
Set fullscreen=() (deny-all).
pub fn set_deny_fullscreen(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_fullscreen(&mut self) -> &mut PermissionsPolicy
Set fullscreen=() (deny-all).
pub fn with_deny_gyroscope(self) -> PermissionsPolicy
pub fn with_deny_gyroscope(self) -> PermissionsPolicy
Set gyroscope=() (deny-all).
pub fn set_deny_gyroscope(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_gyroscope(&mut self) -> &mut PermissionsPolicy
Set gyroscope=() (deny-all).
pub fn with_deny_idle_detection(self) -> PermissionsPolicy
pub fn with_deny_idle_detection(self) -> PermissionsPolicy
Set idle-detection=() (deny-all).
pub fn set_deny_idle_detection(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_idle_detection(&mut self) -> &mut PermissionsPolicy
Set idle-detection=() (deny-all).
pub fn with_deny_magnetometer(self) -> PermissionsPolicy
pub fn with_deny_magnetometer(self) -> PermissionsPolicy
Set magnetometer=() (deny-all).
pub fn set_deny_magnetometer(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_magnetometer(&mut self) -> &mut PermissionsPolicy
Set magnetometer=() (deny-all).
pub fn with_deny_midi(self) -> PermissionsPolicy
pub fn with_deny_midi(self) -> PermissionsPolicy
Set midi=() (deny-all).
pub fn set_deny_midi(&mut self) -> &mut PermissionsPolicy
pub fn set_deny_midi(&mut self) -> &mut PermissionsPolicy
Set midi=() (deny-all).
pub fn with_deny_picture_in_picture(self) -> PermissionsPolicy
pub fn with_deny_picture_in_picture(self) -> PermissionsPolicy
Set picture-in-picture=() (deny-all).
pub 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).
pub fn with_deny_publickey_credentials_get(self) -> PermissionsPolicy
pub fn with_deny_publickey_credentials_get(self) -> PermissionsPolicy
Set publickey-credentials-get=() (deny-all).
pub 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).
pub fn with_deny_screen_wake_lock(self) -> PermissionsPolicy
pub fn with_deny_screen_wake_lock(self) -> PermissionsPolicy
Set screen-wake-lock=() (deny-all).
pub 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).
pub fn with_deny_sync_xhr(self) -> PermissionsPolicy
pub fn with_deny_sync_xhr(self) -> PermissionsPolicy
Set sync-xhr=() (deny-all).
pub 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).
pub fn with_deny_xr_spatial_tracking(self) -> PermissionsPolicy
pub fn with_deny_xr_spatial_tracking(self) -> PermissionsPolicy
Set xr-spatial-tracking=() (deny-all).
pub 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§
§impl Clone for PermissionsPolicy
impl Clone for PermissionsPolicy
§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 more§impl Debug for PermissionsPolicy
impl Debug for PermissionsPolicy
§impl Default for PermissionsPolicy
impl Default for PermissionsPolicy
§fn default() -> PermissionsPolicy
fn default() -> PermissionsPolicy
§impl Display for PermissionsPolicy
impl Display for PermissionsPolicy
impl Eq for PermissionsPolicy
§impl HeaderDecode for PermissionsPolicy
impl HeaderDecode for PermissionsPolicy
§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.§impl HeaderEncode for PermissionsPolicy
impl HeaderEncode for PermissionsPolicy
§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 more§fn encode_to_value(&self) -> Option<HeaderValue>
fn encode_to_value(&self) -> Option<HeaderValue>
HeaderValue. Read more§impl PartialEq for PermissionsPolicy
impl PartialEq for PermissionsPolicy
§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
§impl TypedHeader for PermissionsPolicy
impl TypedHeader for PermissionsPolicy
§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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>
§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,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.
§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writer§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writer§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writer§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writer§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer