Webhook

Trait Webhook 

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

Source

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§

Source

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.

Source

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§

Source§

impl Webhook for DiscordWebhook

Available on crate feature discord only.
Source§

impl Webhook for GitHubWebhook

Available on crate feature github only.
Source§

impl Webhook for SendGridWebhook

Available on crate feature sendgrid only.
Source§

impl Webhook for ShopifyWebhook

Available on crate feature shopify only.
Source§

impl Webhook for SlackWebhook

Available on crate feature slack only.
Source§

impl Webhook for StandardWebhook

Available on crate feature standard only.
Source§

impl Webhook for StripeWebhook

Available on crate feature stripe only.
Source§

impl Webhook for Hmac256Webhook

Available on crate feature hmac only.