Vapid::RequestHeaders
Generates the required HTTP headers for VAPID-authenticated push requests.
Usage
key_pair = Vapid::KeyPair.generate
headers = Vapid::RequestHeaders.new(
audience: "https://fcm.googleapis.com",
subject: "mailto:admin@example.com",
private_key: key_pair
)
# Get headers as a hash
http_headers = headers.to_h
# => {
# "Authorization" => "vapid t=<jwt>, k=<public_key>",
# "Crypto-Key" => "p256ecdsa=<public_key>"
# }
Constructors
new(audience : String, subject : String, private_key : KeyPair, expiration : Time::Span = JWT::DEFAULT_EXPIRATION)
Creates VAPID request headers
Parameters
audience: The origin of the push servicesubject: Contact information (mailto: or https: URL)private_key: KeyPair for signingexpiration: Token validity period (default: 12 hours)
Instance methods
audience
Sourceauthorization_header
Returns the Authorization header value
Format: "vapid t=<jwt_token>, k=<public_key_base64>"
crypto_key_header
Returns the Crypto-Key header value
Format: "p256ecdsa=<public_key_base64>"
Note: This header may be deprecated in favor of the Authorization header but is still supported by many push services
jwt_token
Sourcepublic_key
Sourcesubject
Sourceto_h
Returns headers as a Hash suitable for HTTP::Headers
headers = request_headers.to_h
HTTP::Client.post(url, headers: HTTP::Headers.new(headers), body: payload)