Skip to main content

WebhookReceiver

Struct WebhookReceiver 

Source
pub struct WebhookReceiver { /* private fields */ }
Expand description

Webhook receiver for processing incoming GitHub webhooks.

The receiver coordinates validation, event processing, and handler execution using a fire-and-forget pattern to ensure fast HTTP responses.

§Architecture

  • Validates signatures using SignatureValidator
  • Processes events using EventProcessor
  • Dispatches to registered WebhookHandlers asynchronously
  • Returns HTTP responses within 100ms (target)

§Examples

use github_bot_sdk::webhook::WebhookReceiver;
use github_bot_sdk::auth::SecretProvider;
use github_bot_sdk::events::{EventProcessor, ProcessorConfig};
use std::sync::Arc;

let processor = EventProcessor::new(ProcessorConfig::default());
let receiver = WebhookReceiver::new(secret_provider, processor);

Implementations§

Source§

impl WebhookReceiver

Source

pub fn new(secrets: Arc<dyn SecretProvider>, processor: EventProcessor) -> Self

Create a new webhook receiver.

§Arguments
  • secrets - Provider for retrieving webhook secrets
  • processor - Event processor for normalizing webhooks
§Examples
let processor = EventProcessor::new(ProcessorConfig::default());
let receiver = WebhookReceiver::new(secret_provider, processor);
Source

pub async fn add_handler(&mut self, handler: Arc<dyn WebhookHandler>)

Register a webhook handler.

Handlers are invoked asynchronously after the HTTP response is sent. Multiple handlers can be registered and will execute concurrently.

§Arguments
  • handler - The handler implementation to register
§Examples
let processor = EventProcessor::new(ProcessorConfig::default());
let mut receiver = WebhookReceiver::new(secret_provider, processor);

receiver.add_handler(Arc::new(MyHandler)).await;
Source

pub async fn receive_webhook(&self, request: WebhookRequest) -> WebhookResponse

Process an incoming webhook request.

This is the main entry point for webhook processing. It performs validation, event processing, and returns an immediate HTTP response. Handler execution happens asynchronously after the response is returned.

§Processing Steps
  1. Extract headers (event type, delivery ID, signature)
  2. Validate signature using webhook secret
  3. Process event (parse and normalize)
  4. Return HTTP response immediately
  5. Spawn async task for handlers (fire-and-forget)
§Arguments
  • request - The incoming webhook request
§Returns

HTTP response to send to GitHub

§Errors

Returns error responses for:

  • Missing required headers (BadRequest)
  • Invalid signature (Unauthorized)
  • Malformed payload (BadRequest)
  • Processing failures (InternalError)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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