Documentation
¶
Overview ¶
Package pushd is a small self-hostable Web Push relay. It speaks the two halves of a push service:
- towards application servers, the HTTP Web Push protocol (RFC 8030) with VAPID (RFC 8292): POST /wpush/v2/<token> with TTL, Urgency and Topic headers and an aes128gcm body (RFC 8291);
- towards browsers, the autopush WebSocket protocol (hello, register, unregister, notification, ack, ping).
The relay never sees plaintext: bodies are opaque encrypted records that it stores (while the browser is offline, up to the message's TTL) and forwards. Endpoints are unguessable and unforgeable: an endpoint token is a random endpoint id followed by an HMAC of it under the relay's secret. See docs/push.md.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// PublicURL is the externally visible base URL ("https://push.example.com"), used to build endpoints and as the
// VAPID audience. Empty: derived from each request.
PublicURL string
// Secret keys the endpoint HMACs. Empty: loaded from (or created in) DataDir, else random for this process.
Secret []byte
// DataDir, when set, keeps registrations and undelivered messages across restarts (state.json, mode 0600).
DataDir string
MaxBody int // largest accepted request body (default 4096, RFC 8030 section 7.2)
MaxTTL time.Duration // longest retention (default 30 days)
MaxQueuePerClient int // stored messages per browser (default 100); the oldest is dropped beyond it
MaxChannels int // subscriptions per browser (default 200)
MaxStoredBytes int // all stored bodies together (default 64 MiB); beyond it POST answers 503
ClientExpiry time.Duration // forget a browser not seen for this long (default 60 days)
IdleTimeout time.Duration // close a WebSocket silent for this long (default 10 minutes)
// Rate limits for application servers: requests per second and burst, per source address and per endpoint.
IPRate, IPBurst float64
EndpointRate, EndpointBurst float64
// TrustForwarded takes the client address from X-Forwarded-For (set it only behind your own proxy).
TrustForwarded bool
// RequireVAPID refuses posts without a valid VAPID header even for subscriptions made without a key.
RequireVAPID bool
Now func() time.Time
Logf func(format string, args ...any)
}
Config configures a relay. The zero value works (memory only, random secret) except that endpoints then do not survive a restart.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a relay.
func (*Server) EndpointValid ¶
EndpointValid parses a push endpoint and reports whether its token is valid for this relay.