Skip to main content

AltSvcCache

Struct AltSvcCache 

pub struct AltSvcCache { /* private fields */ }
Available on crate features http and std only.
Expand description

Bounded Alt-Svc advertisements, independent of connector protocol capabilities.

Records retain preference order, protocol and endpoint, including protocols a particular client does not support. Both the number of origins and alternatives per origin are bounded. Lookup shares immutable candidate storage; freshness, persistence and temporary failure state remain private to this cache.

Headers and HTTP/2 ALTSVC frames update the same origin entry: each accepted advertisement replaces the previous list, and either source can clear it. Neither source has precedence. RFC 7838 section 4 discourages mixing them because their processing order can be difficult to predict.

These are hints, not proof of authority. An HTTPS alternative must authenticate the logical origin and negotiate its advertised protocol. Using an alternative for an HTTP origin additionally requires RFC 8164’s origin authorization; TLS authentication alone does not grant that permission.

Share a cache between connectors with the same default authentication policy: endpoint failures are shared as well as advertisements. Middleware excludes request-specific authentication from shared learning and failure updates; opaque per-route configuration is excluded from shared backoff.

Implementations§

§

impl AltSvcCache

pub fn new( capacity: u64, max_age: Duration, failure_backoff: Duration, ) -> AltSvcCache

Set origin capacity, maximum retention and alternative failure backoff.

pub fn with_max_alternatives_per_origin(self, capacity: usize) -> AltSvcCache

Bound retained alternatives per advertisement. Zero disables retention.

Configure this before sharing the cache; existing entries are unaffected.

pub fn set_max_alternatives_per_origin( &mut self, capacity: usize, ) -> &mut AltSvcCache

Bound retained alternatives per advertisement. Zero disables retention.

Configure this before sharing the cache; existing entries are unaffected.

pub fn with_max_advertisement_bytes(self, capacity: usize) -> AltSvcCache

Bound combined Alt-Svc field bytes before parsing or allocating records. Oversized advertisements are ignored, preserving existing cache state.

pub fn set_max_advertisement_bytes( &mut self, capacity: usize, ) -> &mut AltSvcCache

Bound combined Alt-Svc field bytes before parsing or allocating records. Oversized advertisements are ignored, preserving existing cache state.

pub fn record( &self, origin: &HttpOrigin, headers: &HeaderMap, response_delay: Duration, )

Record response hints for their logical origin, including plaintext HTTP.

The caller must establish that these headers belong to this origin. HTTPS responses require origin authentication. Plaintext HTTP can advertise alternatives, but selection must also meet RFC 8164’s origin-authorization requirements; this cache does not perform those checks. response_delay is the time from request dispatch to response headers.

pub fn record_frame( &self, origin: &HttpOrigin, field_value: Bytes, received_at: Instant, )

Record the field value of an HTTP/2 ALTSVC frame for its verified origin.

The caller must validate the frame’s stream/origin association and ensure the connection is authoritative for origin (RFC 7838 section 4). received_at starts the freshness lifetime; delayed delivery does not extend it. Response Age, Date and request latency do not apply to frames. Malformed or oversized values leave existing advertisements unchanged.

pub fn record_frame_received( &self, origin: &HttpOrigin, field_value: Bytes, received: AltSvcReceivedAt, )

Record an authorized frame using its original receive ordering metadata. Custom observers must apply the same origin and shared-policy checks as the response middleware before calling this method.

pub fn record_received( &self, origin: &HttpOrigin, headers: &HeaderMap, response_delay: Duration, received: AltSvcReceivedAt, )

Record a response advertisement in transport receive order. Use the response’s AltSvcReceivedAt when available so delayed header delivery cannot overwrite a newer HTTP/2 ALTSVC frame. The caller must first authorize this origin under the cache’s shared trust policy.

pub fn lookup(&self, origin: &HttpOrigin) -> Option<Arc<HttpServiceCandidates>>

Share a snapshot when at least one candidate is currently usable.

The snapshot retains stable advertisement indices, including candidates that have expired or been suppressed. Call Self::is_usable before attempting each candidate. This avoids rebuilding a vector on every lookup.

pub fn lookup_fresh( &self, origin: &HttpOrigin, ) -> Option<Arc<HttpServiceCandidates>>

Share a fresh snapshot without applying direct-path failure backoff.

Proxy routes can reach alternatives unavailable on the direct path. Use this with Self::is_fresh for proxy route plans, and do not call Self::failed for those attempts.

pub fn is_usable( &self, snapshot: &Arc<HttpServiceCandidates>, index: usize, ) -> bool

Check current freshness and failure state for this exact advertisement. A replaced snapshot or out-of-range index is never usable.

pub fn is_fresh( &self, snapshot: &Arc<HttpServiceCandidates>, index: usize, ) -> bool

Check advertisement freshness independently of direct-path failure state. Used with Self::lookup_fresh for proxy-routed establishment.

pub fn failed(&self, snapshot: &Arc<HttpServiceCandidates>, index: usize)

Temporarily suppress a candidate after direct-path establishment failure.

Do not report proxy-route failures here: reachability can differ by route. Proxy selection uses Self::lookup_fresh instead of this direct-path backoff. Re-advertising an endpoint preserves its failure history.

pub fn network_epoch(&self) -> u64

Capture the current network generation before an attempt or dispatch. Reports from older generations are ignored after Self::network_changed.

pub fn failed_attempt( &self, snapshot: &Arc<HttpServiceCandidates>, index: usize, network: u64, started: Instant, terminal: bool, )

Record a completed attempt even when its endpoint was re-advertised during the dial. A network change invalidates the captured path context.

pub fn route_usable( &self, snapshot: &Arc<HttpServiceCandidates>, index: usize, route: &ProxyRouteContext, ) -> bool

Check freshness and backoff for a particular proxy route plan.

pub fn failed_route( &self, snapshot: &Arc<HttpServiceCandidates>, index: usize, network: u64, started: Instant, route: &ProxyRouteContext, )

Report an unsuccessful connection attempt on the captured route.

pub fn failed_service( &self, service: &EstablishedHttpService, route: Option<&ProxyRouteContext>, network: u64, started: Instant, )

Report a remote response failure under the shared connector policy. Caller cancellation, local body errors and request-only trust failures must not be reported as evidence that this endpoint is unavailable.

pub fn succeeded_service( &self, service: &EstablishedHttpService, route: Option<&ProxyRouteContext>, network: u64, )

A complete response ends the selected path’s failure streak. Merely connecting or receiving response headers does not establish stream health.

pub fn misdirected(&self, snapshot: &Arc<HttpServiceCandidates>, index: usize)

Remove the alternative that returned 421 without replaying a request. Retain failure backoff across repeated advertisements of that endpoint; delayed responses from older discovery generations remain harmless.

pub fn network_changed(&self)

Forget network-specific alternatives while retaining persist=1 entries.

Call this when the application’s network changes (for example, switching interfaces or VPNs). Rama does not monitor operating-system connectivity. This also clears path failure backoff, including persistent alternatives, because reachability on the previous network does not describe the new one.

pub fn clear_all(&self)

Forget all advertisements and failure history, for example when clearing browsing data (RFC 7838 §9.4). Existing connections remain usable; later responses can advertise again. This does not allocate unused stores.

pub fn clear(&self, origin: &HttpOrigin)

Explicitly invalidate this origin’s advertisements.

§

impl AltSvcCache

pub fn frame_observer(&self, origin: HttpOrigin) -> Arc<AltSvcObserverExtension> ⓘ

Observe HTTP/2 advertisements for this logical origin using connection authentication metadata. Install on the connection input before handshake; the observer also handles frames received while requests are idle.

Trait Implementations§

§

impl Clone for AltSvcCache

§

fn clone(&self) -> AltSvcCache

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for AltSvcCache

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for AltSvcCache

§

fn default() -> AltSvcCache

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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

§

fn into_request(self) -> Request<T>

Wrap the input message T in a rama_grpc::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
§

impl<T, U> RamaFrom<T> for U
where U: From<T>,

§

fn rama_from(value: T) -> U

§

impl<T, U, CrateMarker> RamaInto<U, CrateMarker> for T
where U: RamaFrom<T, CrateMarker>,

§

fn rama_into(self) -> U

§

impl<T, U> RamaTryFrom<T> for U
where 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 T
where 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 T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<V, F> ValueFormatter<&V> for F
where F: ValueFormatter<V> + ?Sized, V: ?Sized,

§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
§

fn format_value(writer: impl ValueWriter, value: &&V)

Write value to writer
§

impl<V, F> ValueFormatter<Arc<V>> for F
where F: ValueFormatter<V> + ?Sized, V: ?Sized,

§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
§

fn format_value(writer: impl ValueWriter, value: &Arc<V>)

Write value to writer
§

impl<V, F> ValueFormatter<Box<V>> for F
where F: ValueFormatter<V> + ?Sized, V: ?Sized,

§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
§

fn format_value(writer: impl ValueWriter, value: &Box<V>)

Write value to writer
§

impl<V, F> ValueFormatter<Cow<'_, V>> for F
where V: ToOwned + ?Sized, F: ValueFormatter<V> + ?Sized,

§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
§

fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)

Write value to writer
§

impl<V, F> ValueFormatter<Option<V>> for F
where F: ValueFormatter<V> + ?Sized,

§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
§

fn format_value(writer: impl ValueWriter, value: &Option<V>)

Write value to writer
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more