pub enum RequestAuth<'a> {
Anonymous {
partition: Option<CredentialPartition>,
quota: Option<&'a Arc<QuotaMeter>>,
},
Credential {
header: CredentialHeader<'a>,
partition: CredentialPartition,
on_rate_limit: RateLimitRevocation,
quota: Option<&'a Arc<QuotaMeter>>,
},
}Expand description
The credential state of one origin-confined cached request.
A credentialed body is always stored under a partition derived from the credential, and an
anonymous request never reads it back, so removing or rotating a token cannot make a later
request see a body fetched under the old one. The cache key carries the variant too, so the
same CredentialPartition used with a credential and anonymously yields two entries.
§Examples
use deps_core::cache::{CredentialHeader, CredentialPartition, RequestAuth};
use deps_core::net_policy::TrustedPrefix;
use deps_core::secret::{Redacted, bearer_auth_header};
let prefix = TrustedPrefix::parse("https://index.mycorp.dev/").unwrap();
let token = bearer_auth_header(&Redacted::new("secret-token".to_string()));
let auth = RequestAuth::credential(CredentialHeader::Authorization(&token), &prefix);
assert!(!format!("{auth:?}").contains("secret-token"));
let _anonymous = RequestAuth::anonymous(Some(CredentialPartition::new(1)));Variants§
Anonymous
No credential; partition separates cache entries by the caller’s credential state.
Fields
partition: Option<CredentialPartition>The caller’s credential-state partition, None for the plain per-URL entry.
quota: Option<&'a Arc<QuotaMeter>>The meter fed from the live responses of this request, if any.
Credential
A credential, always cached under its own partition.
Fields
header: CredentialHeader<'a>The header to send.
partition: CredentialPartitionThe partition the response is stored under.
on_rate_limit: RateLimitRevocationWhat a confirmed rate limit on revalidation means for this credential.
quota: Option<&'a Arc<QuotaMeter>>The meter fed from the live responses of this request, if any.
Implementations§
Source§impl<'a> RequestAuth<'a>
impl<'a> RequestAuth<'a>
Sourcepub const fn anonymous(partition: Option<CredentialPartition>) -> Self
pub const fn anonymous(partition: Option<CredentialPartition>) -> Self
An anonymous request stored under partition.
Sourcepub fn credential(header: CredentialHeader<'a>, prefix: &TrustedPrefix) -> Self
pub fn credential(header: CredentialHeader<'a>, prefix: &TrustedPrefix) -> Self
A credentialed request whose partition is a salted digest of prefix and the secret.
Sourcepub const fn credential_in(
header: CredentialHeader<'a>,
partition: CredentialPartition,
) -> Self
pub const fn credential_in( header: CredentialHeader<'a>, partition: CredentialPartition, ) -> Self
A credentialed request stored under a caller-chosen partition.
Sourcepub const fn with_rate_limit(self, on_rate_limit: RateLimitRevocation) -> Self
pub const fn with_rate_limit(self, on_rate_limit: RateLimitRevocation) -> Self
Sets what a confirmed rate limit means for this request’s credential. No effect on an anonymous request.
Sourcepub const fn with_quota_meter(self, meter: &'a Arc<QuotaMeter>) -> Self
pub const fn with_quota_meter(self, meter: &'a Arc<QuotaMeter>) -> Self
Feeds meter from the rate-limit headers of every response this request receives over
the network, whichever variant it is.
Recording happens inside the fetch layer when a response arrives, never from a stored cache entry, so a stale reading cannot be replayed into the meter.