pub struct CachingCardResolver { /* private fields */ }Expand description
A caching agent card resolver: a private HTTP cache (RFC 9111) of one agent card (spec §8.6.2: clients SHOULD honor RFC 9111 when fetching Agent Cards).
resolve returns the stored card without a request
while it is fresh: for its Cache-Control: max-age, or else its
Expires, less the age it arrived with (Age, Date). A stale card is
revalidated with If-None-Match / If-Modified-Since, and a card marked
no-cache or Vary: * is revalidated on every resolve. A no-store
card is not stored. Directives for shared caches (s-maxage,
proxy-revalidate) do not apply to it.
A card with no max-age and no Expires is revalidated on every
resolve unless with_default_freshness
gives it a lifetime (with no ETag or Last-Modified either, that is a
full fetch each time, and the card is kept only to be served stale, below),
and
with_always_revalidate revalidates
even a fresh card, so a card the agent changes is seen at once.
§At fleet scale (ADR 0051)
- A resolver builds its HTTP client once, so a revalidation reuses the
connection of the fetch before it;
with_pooluses anHttpPool’s connections instead. - While a fetch is running, other
resolvecalls on the resolver and its clones wait for it and share its outcome: N callers holding a stale card make one request. - A revalidation that fails because the agent cannot be reached, timed
out, or answered
500/502/503/504returns the stored card if it went stale no longer ago than the stale-if-error window (RFC 5861): the larger ofwith_stale_if_errorand the card’s ownCache-Control: stale-if-error. A card markedmust-revalidateorno-cacheis never returned stale. A card with no lifetime is stale from the moment it arrives, so the window counts from then, and it is kept (when it has no validator either) only if a window can apply to it. with_refresh_jitterspreads the revalidations of processes that fetched together.
A CardCache holds one resolver per URL for many peers.
Clones share one cache. A resolver fetches the public card only, with
the same request headers every time; with_options
starts a new cache, so a card stored under one credential is never
returned for another.
Implementations§
Source§impl CachingCardResolver
impl CachingCardResolver
Sourcepub fn new(base_url: &str) -> Result<CachingCardResolver, ClientError>
pub fn new(base_url: &str) -> Result<CachingCardResolver, ClientError>
Creates a new resolver for the given agent card URL.
§Errors
Returns ClientError::InvalidEndpoint if base_url is malformed
(empty, missing scheme, etc.).
Sourcepub fn with_path(
base_url: &str,
path: &str,
) -> Result<CachingCardResolver, ClientError>
pub fn with_path( base_url: &str, path: &str, ) -> Result<CachingCardResolver, ClientError>
Creates a new resolver with a custom path.
§Errors
Returns ClientError::InvalidEndpoint if base_url is malformed.
Sourcepub fn with_options(self, options: CardFetchOptions) -> CachingCardResolver
pub fn with_options(self, options: CardFetchOptions) -> CachingCardResolver
Fetches with options: their headers and budget, and, with
signing, their signature keys, so a card that does not verify is
never cached or returned (spec §14: clients SHOULD verify signatures
when present). Default: CardFetchOptions::default.
Starts a new, empty cache, with no extended card installed. A card stored for other request headers, another credential’s, is not a response to this resolver’s requests (RFC 9111 §4.1), and the cache it would otherwise keep is shared with every clone.
Sourcepub fn with_pool(self, pool: &HttpPool) -> CachingCardResolver
Available on crate feature tls-rustls only.
pub fn with_pool(self, pool: &HttpPool) -> CachingCardResolver
tls-rustls only.Fetches through pool’s connections (ADR 0032 decision 6), shared
with every client and resolver given the same pool. The cache is
kept: the connection a response arrived on does not change it.
A pool has one TLS configuration, so options that carry their own
(CardFetchOptions::with_tls_config) conflict with it: every
resolve then fails with ClientError::Config naming both, rather
than ignoring one.
Sourcepub const fn with_always_revalidate(self, always: bool) -> CachingCardResolver
pub const fn with_always_revalidate(self, always: bool) -> CachingCardResolver
Whether every resolve revalidates the stored card,
however long the server said it stays fresh. Default: false.
true is how the resolver behaved before 0.15: a request on every
resolve, a 304 when the card is unchanged. It suits an agent whose
card changes without notice (a hot-reloaded card served with a long
max-age), at a round trip per resolve. RFC 9111 allows a cache to
validate a fresh response at any time.
Sourcepub const fn with_default_freshness(
self,
lifetime: Duration,
) -> CachingCardResolver
pub const fn with_default_freshness( self, lifetime: Duration, ) -> CachingCardResolver
How long a card stays fresh when its response says nothing about it:
no max-age and no Expires (spec §8.6.2: when the server does not
include caching headers, clients MAY apply an implementation-specific
default cache duration). Default: none, so such a card is
revalidated on every resolve.
The lifetime counts from when the card arrived, less any Age it
arrived with, and is capped at 2^31 seconds (RFC 9111 §1.2.2). It is
never applied to a card marked no-cache or no-store.
Sourcepub const fn with_stale_if_error(self, window: Duration) -> CachingCardResolver
pub const fn with_stale_if_error(self, window: Duration) -> CachingCardResolver
How long after it went stale the stored card may still be returned
when its revalidation fails because the agent could not be reached,
timed out, or answered 500, 502, 503 or 504 (RFC 5861 §4).
Default: none, so only the card’s own stale-if-error directive
allows it.
The window used is the larger of this and that directive. A card
marked must-revalidate or no-cache is never returned stale, and a
failure of another kind (a 404, a card that does not parse or
verify) is returned as the error it is.
Sourcepub const fn with_refresh_jitter(self, fraction: f64) -> CachingCardResolver
pub const fn with_refresh_jitter(self, fraction: f64) -> CachingCardResolver
Shortens each stored card’s freshness by a random share of up to
fraction of its lifetime, drawn when the card is stored, so that
processes which fetched a card together revalidate it apart. Never
lengthens it. fraction is clamped to 0.0..=0.5; not a number is
0.0. Default: 0.0 (a CardCache uses 0.1).
Sourcepub async fn resolve(&self) -> Result<AgentCard, ClientError>
pub async fn resolve(&self) -> Result<AgentCard, ClientError>
Resolves the agent card, using the stored one while it is fresh.
Returns the stored card without a request while it is fresh. Otherwise
fetches, with conditional request headers when a card is stored: on
304, returns the stored card, now as fresh as the 304 says; on
200, stores and returns the new card. Concurrent calls share one
fetch, and a fetch that fails for want of the agent may return the
stored card (see with_stale_if_error).
§Errors
Same conditions as resolve_agent_card, and
ClientError::Config when with_pool and
options with their own TLS configuration were both given.
Sourcepub async fn invalidate(&self)
pub async fn invalidate(&self)
Clears the internal cache, the extended card included.
Sourcepub async fn install_extended_card(&self, card: AgentCard)
pub async fn install_extended_card(&self, card: AgentCard)
Uses card, the extended card from GetExtendedAgentCard, in place
of the public one until clear_extended_card
(spec §13.3: clients SHOULD replace their cached public card with the
extended version for the duration of their authenticated session).
While it is installed, resolve returns it without
fetching.
Sourcepub async fn clear_extended_card(&self)
pub async fn clear_extended_card(&self)
Ends the authenticated session’s view: resolve
goes back to the public card.
Whether self and other share one cache (one is a clone of the
other, or both came from one CardCache for one URL).
Trait Implementations§
Source§impl Clone for CachingCardResolver
impl Clone for CachingCardResolver
Source§fn clone(&self) -> CachingCardResolver
fn clone(&self) -> CachingCardResolver
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for CachingCardResolver
impl !UnwindSafe for CachingCardResolver
impl Forget for CachingCardResolver
impl Freeze for CachingCardResolver
impl Move for CachingCardResolver
impl Send for CachingCardResolver
impl Sync for CachingCardResolver
impl Unpin for CachingCardResolver
impl UnsafeUnpin for CachingCardResolver
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> 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 tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].