pub struct MeteringMiddleware<Q, U> { /* private fields */ }Expand description
Middleware that enforces quotas pre-dispatch and records usage post-dispatch.
Generic over the quota checker Q and usage recorder U, allowing
integrators to bring their own storage backends.
§Request flow
- Extract
Content-Lengthfrom request headers as a byte estimate. - Call
QuotaChecker::check_quota— reject with 429 if over limit. - Delegate to the next middleware via
Next::run. - In
after_dispatch, callUsageRecorder::record_operationwith the actual response metadata.
Implementations§
Source§impl<Q, U> MeteringMiddleware<Q, U>
impl<Q, U> MeteringMiddleware<Q, U>
Trait Implementations§
Source§impl<Q: QuotaChecker, U: UsageRecorder> Middleware for MeteringMiddleware<Q, U>
impl<Q: QuotaChecker, U: UsageRecorder> Middleware for MeteringMiddleware<Q, U>
Source§async fn handle<'a>(
&'a self,
ctx: DispatchContext<'a>,
next: Next<'a>,
) -> Result<HandlerAction, ProxyError>
async fn handle<'a>( &'a self, ctx: DispatchContext<'a>, next: Next<'a>, ) -> Result<HandlerAction, ProxyError>
Handle a request, optionally delegating to the next middleware via
Next::run.Source§fn after_dispatch(
&self,
completed: &CompletedRequest<'_>,
) -> impl Future<Output = ()> + MaybeSend + '_
fn after_dispatch( &self, completed: &CompletedRequest<'_>, ) -> impl Future<Output = ()> + MaybeSend + '_
Called after the request has been fully dispatched and the response is
available. Use this for logging, metering, or other post-dispatch
side effects. The default implementation is a no-op.
Auto Trait Implementations§
impl<Q, U> Freeze for MeteringMiddleware<Q, U>
impl<Q, U> RefUnwindSafe for MeteringMiddleware<Q, U>where
Q: RefUnwindSafe,
U: RefUnwindSafe,
impl<Q, U> Send for MeteringMiddleware<Q, U>
impl<Q, U> Sync for MeteringMiddleware<Q, U>
impl<Q, U> Unpin for MeteringMiddleware<Q, U>
impl<Q, U> UnsafeUnpin for MeteringMiddleware<Q, U>where
Q: UnsafeUnpin,
U: UnsafeUnpin,
impl<Q, U> UnwindSafe for MeteringMiddleware<Q, U>where
Q: UnwindSafe,
U: UnwindSafe,
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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 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>
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