Expand description
Webhook receiver for HTTP intake and async processing coordination.
This module provides the core webhook receiving functionality that applications use to accept GitHub webhooks, validate them, and dispatch to handlers. The receiver implements the fire-and-forget pattern to ensure fast HTTP responses.
§Fire-and-Forget Pattern
The receiver follows this pattern:
- Extract headers and payload from HTTP request (fast)
- Validate signature (fast, ~10ms)
- Process/normalize event (fast, ~5ms)
- Return HTTP response immediately (target <100ms total)
- Spawn async tasks for handlers (non-blocking)
This ensures GitHub receives a response within the 10-second timeout while allowing handlers to perform longer operations.
§Examples
use github_bot_sdk::webhook::{WebhookReceiver, WebhookHandler, WebhookRequest};
use github_bot_sdk::auth::SecretProvider;
use github_bot_sdk::events::{EventProcessor, ProcessorConfig};
use std::sync::Arc;
use std::collections::HashMap;
// Create receiver with dependencies
let processor = EventProcessor::new(ProcessorConfig::default());
let receiver = WebhookReceiver::new(secret_provider, processor);
// Register handlers
// receiver.add_handler(my_handler);
// Process incoming webhook
let headers = HashMap::from([
("x-github-event".to_string(), "pull_request".to_string()),
("x-github-delivery".to_string(), "12345".to_string()),
("x-hub-signature-256".to_string(), "sha256=abc...".to_string()),
]);
let body = bytes::Bytes::from_static(b"{\"action\":\"opened\"}");
let request = WebhookRequest::new(headers, body);
let response = receiver.receive_webhook(request).await;
println!("Status: {}", response.status_code());Structs§
- Webhook
Receiver - Webhook receiver for processing incoming GitHub webhooks.
- Webhook
Request - Raw HTTP webhook request data.
Enums§
- Webhook
Response - HTTP response for webhook requests.