Skip to main content

WebhookReceiver

Struct WebhookReceiver 

Source
pub struct WebhookReceiver { /* private fields */ }
Available on crate feature 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:

  1. its notification token, under either header name, must belong to a registered config (looked up by digest, compared in constant time) — else 401;
  2. if that config has authentication, the Authorization header must be its scheme (any case) and credentials (constant time) — else 401;
  3. if a rate limit is set, the config’s bucket must not be empty — else 429;
  4. the body must parse as a StreamResponse — else 400;
  5. the event’s task must be the config’s task — else 403;
  6. 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

Source

pub fn new() -> WebhookReceiver

A receiver with no configs, duplicate detection on (10 000 bodies, one hour) and no rate limit.

Source

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.

Source

pub fn without_dedup(self) -> WebhookReceiver

Hands every valid request over as Accepted, retries included.

Source

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.

Source

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.

Source

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.

Source

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

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for WebhookReceiver

Source§

fn default() -> WebhookReceiver

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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 tonic::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> 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, 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<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