Crate web_push

Source
Expand description

§Web Push

A library for creating and sending push notifications to a web browser. For content payload encryption it uses RFC8188. The client is asynchronous and can run on any executor. An optional hyper based client is available with the feature hyper-client.

§Example

let endpoint = "https://updates.push.services.mozilla.com/wpush/v1/...";
let p256dh = "key_from_browser_as_base64";
let auth = "auth_from_browser_as_base64";

//You would likely get this by deserializing a browser `pushSubscription` object.  
let subscription_info = SubscriptionInfo::new(
    endpoint,
    p256dh,
    auth
);

//Read signing material for payload.
let file = File::open("private.pem").unwrap();
let mut sig_builder = VapidSignatureBuilder::from_pem(file, &subscription_info)?.build()?;

//Now add payload and encrypt.
let mut builder = WebPushMessageBuilder::new(&subscription_info);
let content = "Encrypted payload to be sent in the notification".as_bytes();
builder.set_payload(ContentEncoding::Aes128Gcm, content);
builder.set_vapid_signature(sig_builder);

let client = IsahcWebPushClient::new()?;

//Finally, send the notification!
client.send(builder.build()?).await?;

Modules§

request_builder
Functions used to send and consume push http messages. This module can be used to build custom clients.

Structs§

Config
Contains configuration parameters for base64 encoding
IsahcWebPushClient
An async client for sending the notification payload. This client is expensive to create, and should be reused.
PartialVapidSignatureBuilder
A VapidSignatureBuilder without VAPID subscription info.
SubscriptionInfo
Client info for sending the notification. Maps the values from browser’s subscription info JSON data (AKA pushSubscription object).
SubscriptionKeys
Encryption keys from the client.
VapidSignature
A struct representing a VAPID signature. Should be generated using the VapidSignatureBuilder.
VapidSignatureBuilder
A VAPID signature builder for generating an optional signature to the request. This encryption is required for payloads in all current and future browsers.
WebPushMessage
Everything needed to send a push notification to the user.
WebPushMessageBuilder
The main class for creating a notification payload.
WebPushPayload
The push content payload, already in an encrypted form.

Enums§

ContentEncoding
Content encoding profiles.
Urgency
WebPushError

Constants§

BCRYPT
Bcrypt character set
BINHEX
BinHex character set
CRYPT
As per crypt(3) requirements
IMAP_MUTF7
IMAP modified UTF-7 requirements
STANDARD
Standard character set with padding.
STANDARD_NO_PAD
Standard character set without padding.
URL_SAFE
URL-safe character set with padding
URL_SAFE_NO_PAD
URL-safe character set without padding

Traits§

WebPushClient
An async client for sending the notification payload. Other features, such as thread safety, may vary by implementation.