pub trait Webhook {
// Required method
fn validate_body(
&self,
req: &Request<'_>,
body_reader: impl AsyncRead + Unpin + Send + Sync,
time_bounds: (u32, u32),
) -> impl Future<Output = Outcome<'_, Vec<u8>, WebhookError>> + Send + Sync;
// Provided methods
fn validate_timestamp(
&self,
timestamp: &str,
(min, max): (u32, u32),
) -> Outcome<'_, (), WebhookError> { ... }
fn get_header<'r>(
&self,
req: &'r Request<'_>,
name: &str,
prefix: Option<&str>,
) -> Outcome<'_, &'r str, WebhookError> { ... }
}
Expand description
Base interface for all webhooks
Required Methods§
Sourcefn validate_body(
&self,
req: &Request<'_>,
body_reader: impl AsyncRead + Unpin + Send + Sync,
time_bounds: (u32, u32),
) -> impl Future<Output = Outcome<'_, Vec<u8>, WebhookError>> + Send + Sync
fn validate_body( &self, req: &Request<'_>, body_reader: impl AsyncRead + Unpin + Send + Sync, time_bounds: (u32, u32), ) -> impl Future<Output = Outcome<'_, Vec<u8>, WebhookError>> + Send + Sync
Read body and validate webhook. If the webhook uses a timestamp, verify that it is within the expected bounds (bounds are in unix epoch seconds).
Provided Methods§
Sourcefn validate_timestamp(
&self,
timestamp: &str,
(min, max): (u32, u32),
) -> Outcome<'_, (), WebhookError>
fn validate_timestamp( &self, timestamp: &str, (min, max): (u32, u32), ) -> Outcome<'_, (), WebhookError>
Validate a timestamp against the given bounds. The default implementation assumes that it is in Unix epoch seconds, and returns a Bad Request error if it is invalid.
Sourcefn get_header<'r>(
&self,
req: &'r Request<'_>,
name: &str,
prefix: Option<&str>,
) -> Outcome<'_, &'r str, WebhookError>
fn get_header<'r>( &self, req: &'r Request<'_>, name: &str, prefix: Option<&str>, ) -> Outcome<'_, &'r str, WebhookError>
Retrieve a header that’s expected for a webhook request. The default implementation looks for the header and returns a Bad Request error if it was not provided. It can also optionally strip a given prefix.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl Webhook for DiscordWebhook
Available on crate feature
discord
only.impl Webhook for GitHubWebhook
Available on crate feature
github
only.impl Webhook for SendGridWebhook
Available on crate feature
sendgrid
only.impl Webhook for ShopifyWebhook
Available on crate feature
shopify
only.impl Webhook for SlackWebhook
Available on crate feature
slack
only.impl Webhook for StandardWebhook
Available on crate feature
standard
only.impl Webhook for StripeWebhook
Available on crate feature
stripe
only.impl Webhook for Hmac256Webhook
Available on crate feature
hmac
only.