MCPcopy Index your code
hub / github.com/coder/coder / Test

Method Test

coderd/webpush/webpush.go:429–452  ·  view source on GitHub ↗
(ctx context.Context, req codersdk.WebpushSubscription)

Source from the content-addressed store, hash-verified

427}
428
429func (n *Webpusher) Test(ctx context.Context, req codersdk.WebpushSubscription) error {
430 msgJSON, err := json.Marshal(codersdk.WebpushMessage{
431 Title: "It's working!",
432 Body: "You've subscribed to push notifications.",
433 })
434 if err != nil {
435 return xerrors.Errorf("marshal webpush notification: %w", err)
436 }
437 statusCode, body, err := n.webpushSend(ctx, msgJSON, req.Endpoint, webpush.Keys{
438 Auth: req.AuthKey,
439 P256dh: req.P256DHKey,
440 })
441 if err != nil {
442 return xerrors.Errorf("send test webpush notification: %w", err)
443 }
444
445 // 200, 201, and 202 are common for successful delivery.
446 if statusCode > http.StatusAccepted {
447 // It's likely the subscription failed to deliver for some reason.
448 return xerrors.Errorf("web push dispatch failed with status code %d: %s", statusCode, string(body))
449 }
450
451 return nil
452}
453
454// PublicKey returns the VAPID public key for the webpush dispatcher.
455// Clients need this, so it's exposed via the BuildInfo endpoint.

Callers

nothing calls this directly

Calls 3

webpushSendMethod · 0.95
MarshalMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected