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
impl WebhookReceiver
Sourcepub fn new(secrets: Arc<dyn SecretProvider>, processor: EventProcessor) -> Self
pub fn new(secrets: Arc<dyn SecretProvider>, processor: EventProcessor) -> Self
Sourcepub async fn add_handler(&mut self, handler: Arc<dyn WebhookHandler>)
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;Sourcepub async fn receive_webhook(&self, request: WebhookRequest) -> WebhookResponse
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
- Extract headers (event type, delivery ID, signature)
- Validate signature using webhook secret
- Process event (parse and normalize)
- Return HTTP response immediately
- 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§
impl Freeze 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§
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