pub struct WebhookReceiver { /* private fields */ }webhook only.Expand description
Checks webhook requests against the push configs a client registered (spec §4.3.3, §13.2).
Each request to receive goes through, in order:
- its notification token, under either header name, must belong to a registered config (looked up by digest, compared in constant time) — else 401;
- if that config has
authentication, theAuthorizationheader must be its scheme (any case) and credentials (constant time) — else 401; - if a rate limit is set, the config’s bucket must not be empty — else 429;
- the body must parse as a
StreamResponse— else 400; - the event’s task must be the config’s task — else 403;
- a body already accepted for this config is a
Duplicate, answered 200 and not handed over again.
Thread-safe; share it behind an Arc.
Implementations§
Source§impl WebhookReceiver
impl WebhookReceiver
Sourcepub fn new() -> WebhookReceiver
pub fn new() -> WebhookReceiver
A receiver with no configs, duplicate detection on (10 000 bodies, one hour) and no rate limit.
Sourcepub fn with_dedup(self, max_entries: usize, ttl: Duration) -> WebhookReceiver
pub fn with_dedup(self, max_entries: usize, ttl: Duration) -> WebhookReceiver
Remembers at most max_entries accepted bodies, each for ttl.
The bound is on memory: past it the oldest is forgotten, and a retry of that one is accepted again.
Sourcepub fn without_dedup(self) -> WebhookReceiver
pub fn without_dedup(self) -> WebhookReceiver
Hands every valid request over as Accepted, retries included.
Sourcepub const fn with_rate_limit(self, per_sec: u32, burst: u32) -> WebhookReceiver
pub const fn with_rate_limit(self, per_sec: u32, burst: u32) -> WebhookReceiver
Limits each config to per_sec requests a second, with bursts of up
to burst (at least 1). Off by default.
Counted after the token and Authorization checks, so requests
without the config’s secrets cannot spend its allowance. Applies to
configs registered after this call.
Sourcepub fn register(
&self,
config: &TaskPushNotificationConfig,
) -> Result<(), WebhookError>
pub fn register( &self, config: &TaskPushNotificationConfig, ) -> Result<(), WebhookError>
Expects notifications for config, identified by its token.
Register the config as the agent stored it — what create_push_config
returns, with the id the agent assigned. Registering a config with
the same task and id again replaces it (a rotated token, say).
§Errors
WebhookError when the config has no token or one that cannot be
sent as a header, names no task, has authentication without
credentials, or uses a token another registered config already has.
Sourcepub fn unregister(&self, task_id: &str, config_id: Option<&str>) -> bool
pub fn unregister(&self, task_id: &str, config_id: Option<&str>) -> bool
Stops expecting notifications for the config with this task and id;
false if there was none. Requests carrying its token are then
refused as WebhookRejection::UnknownToken.
Sourcepub fn receive(&self, headers: &HeaderMap, body: &[u8]) -> WebhookOutcome
pub fn receive(&self, headers: &HeaderMap, body: &[u8]) -> WebhookOutcome
Checks one webhook request and says what to do with it.
body is the request body as received. Bound its size before
reading it; this takes what it is given.
Runs in a span, a2a.webhook.receive, that continues the sender’s
trace when no recorded span is current (span.rs).
Trait Implementations§
Source§impl Debug for WebhookReceiver
impl Debug for WebhookReceiver
Source§impl Default for WebhookReceiver
impl Default for WebhookReceiver
Source§fn default() -> WebhookReceiver
fn default() -> WebhookReceiver
Auto Trait Implementations§
impl !Freeze for WebhookReceiver
impl Forget for WebhookReceiver
impl Move for WebhookReceiver
impl RefUnwindSafe for WebhookReceiver
impl Send for WebhookReceiver
impl Sync for WebhookReceiver
impl Unpin for WebhookReceiver
impl UnsafeUnpin for WebhookReceiver
impl UnwindSafe for WebhookReceiver
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
§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].