@@ -2,6 +2,7 @@ package webpush
2
2
3
3
import (
4
4
"bytes"
5
+ "context"
5
6
"crypto/aes"
6
7
"crypto/cipher"
7
8
"crypto/elliptic"
@@ -62,10 +63,15 @@ type Subscription struct {
62
63
Keys Keys `json:"keys"`
63
64
}
64
65
65
- // SendNotification sends a push notification to a subscription's endpoint
66
+ // SendNotification calls SendNotificationWithContext with default context for backwards-compatibility
67
+ func SendNotification (message []byte , s * Subscription , options * Options ) (* http.Response , error ) {
68
+ return SendNotificationWithContext (context .Background (), message , s , options )
69
+ }
70
+
71
+ // SendNotificationWithContext sends a push notification to a subscription's endpoint
66
72
// Message Encryption for Web Push, and VAPID protocols.
67
73
// FOR MORE INFORMATION SEE RFC8291: https://datatracker.ietf.org/doc/rfc8291
68
- func SendNotification ( message []byte , s * Subscription , options * Options ) (* http.Response , error ) {
74
+ func SendNotificationWithContext ( ctx context. Context , message []byte , s * Subscription , options * Options ) (* http.Response , error ) {
69
75
// Authentication secret (auth_secret)
70
76
authSecret , err := decodeSubscriptionKey (s .Keys .Auth )
71
77
if err != nil {
@@ -182,6 +188,10 @@ func SendNotification(message []byte, s *Subscription, options *Options) (*http.
182
188
return nil , err
183
189
}
184
190
191
+ if ctx != nil {
192
+ req = req .WithContext (ctx )
193
+ }
194
+
185
195
req .Header .Set ("Content-Encoding" , "aes128gcm" )
186
196
req .Header .Set ("Content-Length" , strconv .Itoa (len (ciphertext )))
187
197
req .Header .Set ("Content-Type" , "application/octet-stream" )
0 commit comments