Struct SecPurpose
pub struct SecPurpose { /* private fields */ }http and std only.Expand description
The Sec-Purpose request header.
Sent by browsers on a speculative request: something fetched before the
user asked for it. The header is a Structured Field List (RFC 9651) with
a member that is the token prefetch, optionally with parameters:
prefetch:<link rel=prefetch>or a speculation-rules prefetch.prefetch;prerender: a speculation-rules prerender, or one the browser started itself (e.g. from the address bar).prefetch;anonymous-client-ip: a prefetch sent through a private prefetch proxy, hiding the client’s IP address.
A parameter is set by any value but ?0, and unknown parameters are
ignored. Several field lines combine into one List. The first prefetch
member is read, wherever it is; without one, a first member that is
another token (prefetch matches case-sensitively) is kept as
SecPurposeKind::Unknown, and anything else is invalid.
The legacy spellings Purpose: prefetch, X-Purpose: preview (Safari)
and X-Moz: prefetch (older Firefox) are separate headers this type does
not read.
It is not one of the Fetch Metadata headers, but describes the same
request context; FetchMetadata carries it alongside them.
§Example
use rama_http_headers::{HeaderMapExt, SecPurpose};
use rama_http_types::HeaderMap;
let mut headers = HeaderMap::new();
headers.typed_insert(SecPurpose::prerender());
assert_eq!(headers["sec-purpose"], "prefetch;prerender");
let purpose: SecPurpose = headers.typed_get().unwrap();
assert!(purpose.is_prefetch());
assert!(purpose.is_prerender());
assert!(!purpose.anonymous_client_ip());Implementations§
§impl SecPurpose
impl SecPurpose
pub const fn new(kind: SecPurposeKind) -> SecPurpose
pub const fn new(kind: SecPurposeKind) -> SecPurpose
A purpose of kind, without parameters.
pub const fn prefetch() -> SecPurpose
pub const fn prefetch() -> SecPurpose
prefetch: a speculative fetch of a resource or document.
pub const fn prerender() -> SecPurpose
pub const fn prerender() -> SecPurpose
prefetch;prerender: a speculative fetch that is also rendered.
pub fn kind(&self) -> &SecPurposeKind
pub fn kind(&self) -> &SecPurposeKind
The purpose token.
pub fn is_prefetch(&self) -> bool
pub fn is_prefetch(&self) -> bool
Whether the purpose token is prefetch.
A prerender is a prefetch on the wire, so this holds for it as well.
pub const fn is_prerender(&self) -> bool
pub const fn is_prerender(&self) -> bool
Whether the prerender parameter is set: the browser renders the
response in the background, running its scripts.
pub const fn anonymous_client_ip(&self) -> bool
pub const fn anonymous_client_ip(&self) -> bool
Whether the anonymous-client-ip parameter is set: the request went
through a private prefetch proxy, so the peer address is the proxy’s,
not the client’s.
pub const fn with_prerender(self, prerender: bool) -> SecPurpose
pub const fn with_prerender(self, prerender: bool) -> SecPurpose
Set the prerender parameter.
pub fn set_prerender(&mut self, prerender: bool) -> &mut SecPurpose
pub fn set_prerender(&mut self, prerender: bool) -> &mut SecPurpose
Set the prerender parameter.
pub const fn with_anonymous_client_ip(
self,
anonymous_client_ip: bool,
) -> SecPurpose
pub const fn with_anonymous_client_ip( self, anonymous_client_ip: bool, ) -> SecPurpose
Set the anonymous-client-ip parameter.
pub fn set_anonymous_client_ip(
&mut self,
anonymous_client_ip: bool,
) -> &mut SecPurpose
pub fn set_anonymous_client_ip( &mut self, anonymous_client_ip: bool, ) -> &mut SecPurpose
Set the anonymous-client-ip parameter.
Trait Implementations§
§impl Clone for SecPurpose
impl Clone for SecPurpose
§fn clone(&self) -> SecPurpose
fn clone(&self) -> SecPurpose
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 SecPurpose
impl Debug for SecPurpose
§impl<'de> Deserialize<'de> for SecPurpose
impl<'de> Deserialize<'de> for SecPurpose
§fn deserialize<D>(
deserializer: D,
) -> Result<SecPurpose, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<SecPurpose, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
§impl Display for SecPurpose
impl Display for SecPurpose
impl Eq for SecPurpose
§impl FromStr for SecPurpose
impl FromStr for SecPurpose
§impl Hash for SecPurpose
impl Hash for SecPurpose
§impl HeaderDecode for SecPurpose
impl HeaderDecode for SecPurpose
§fn decode<'i, I>(values: &mut I) -> Result<SecPurpose, Error>where
I: Iterator<Item = &'i HeaderValue>,
fn decode<'i, I>(values: &mut I) -> Result<SecPurpose, Error>where
I: Iterator<Item = &'i HeaderValue>,
HeaderValues.§impl HeaderEncode for SecPurpose
impl HeaderEncode for SecPurpose
§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 SecPurpose
impl PartialEq for SecPurpose
§impl Serialize for SecPurpose
impl Serialize for SecPurpose
§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl StructuralPartialEq for SecPurpose
§impl TypedHeader for SecPurpose
impl TypedHeader for SecPurpose
§fn name() -> &'static HeaderName
fn name() -> &'static HeaderName
Auto Trait Implementations§
impl Freeze for SecPurpose
impl RefUnwindSafe for SecPurpose
impl Send for SecPurpose
impl Sync for SecPurpose
impl Unpin for SecPurpose
impl UnsafeUnpin for SecPurpose
impl UnwindSafe for SecPurpose
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<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§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
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<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.