@@ -34,21 +34,20 @@ var saltFunc = func() ([]byte, error) {
34
34
return salt , nil
35
35
}
36
36
37
- // httpClient is an interface for sending the notification HTTP request / testing
38
- type httpClient interface {
37
+ // HTTPClient is an interface for sending the notification HTTP request / testing
38
+ type HTTPClient interface {
39
39
Do (* http.Request ) (* http.Response , error )
40
40
}
41
41
42
42
// Options are config and extra params needed to send a notification
43
43
type Options struct {
44
- httpClient httpClient
45
-
46
- Subscriber string // Sub in VAPID JWT token
47
- Topic string // Set the Topic header to collapse a pending messages (Optional)
48
- TTL int // Set the TTL on the endpoint POST request
49
- Urgency Urgency // Set the Urgency header to change a message priority (Optional)
50
- VAPIDPublicKey string // VAPID public key, passed in VAPID Authorization header
51
- VAPIDPrivateKey string // VAPID private key, used to sign VAPID JWT token
44
+ HTTPClient HTTPClient // Will replace with *http.Client by default if not included
45
+ Subscriber string // Sub in VAPID JWT token
46
+ Topic string // Set the Topic header to collapse a pending messages (Optional)
47
+ TTL int // Set the TTL on the endpoint POST request
48
+ Urgency Urgency // Set the Urgency header to change a message priority (Optional)
49
+ VAPIDPublicKey string // VAPID public key, passed in VAPID Authorization header
50
+ VAPIDPrivateKey string // VAPID private key, used to sign VAPID JWT token
52
51
}
53
52
54
53
// Keys are the base64 encoded values from PushSubscription.getKey()
@@ -201,11 +200,14 @@ func SendNotification(message []byte, s *Subscription, options *Options) (*http.
201
200
req .Header .Set ("Authorization" , vapidAuthHeader )
202
201
203
202
// Send the request
204
- if options .httpClient == nil {
205
- options .httpClient = & http.Client {}
203
+ var client HTTPClient
204
+ if options .HTTPClient != nil {
205
+ client = options .HTTPClient
206
+ } else {
207
+ client = & http.Client {}
206
208
}
207
209
208
- return options . httpClient .Do (req )
210
+ return client .Do (req )
209
211
}
210
212
211
213
// decodeSubscriptionKey decodes a base64 subscription key.
0 commit comments