@@ -154,36 +154,30 @@ function sendNotification(endpoint, params) {
154
154
} ;
155
155
156
156
var encrypted ;
157
- var useCryptoKey = false ;
158
157
if ( typeof payload !== 'undefined' ) {
159
158
var encodingHeader ;
159
+ var cryptoHeaderName ;
160
160
161
161
if ( userAuth ) {
162
- useCryptoKey = true ;
163
-
164
162
// Use the new standard if userAuth is defined (Firefox 46+ and Chrome 50+).
165
163
encrypted = encrypt ( userPublicKey , userAuth , new Buffer ( payload ) ) ;
166
164
encodingHeader = 'aesgcm' ;
165
+ cryptoHeaderName = 'Crypto-Key' ;
167
166
} else {
168
167
// Use the old standard if userAuth isn't defined (up to Firefox 45).
169
168
encrypted = encryptOld ( userPublicKey , new Buffer ( payload ) ) ;
170
169
encodingHeader = 'aesgcm128' ;
170
+ cryptoHeaderName = 'Encryption-Key' ;
171
171
}
172
172
173
173
options . headers = {
174
174
'Content-Length' : encrypted . cipherText . length ,
175
175
'Content-Type' : 'application/octet-stream' ,
176
+ 'Content-Encoding' : encodingHeader ,
176
177
'Encryption' : 'keyid=p256dh;salt=' + encrypted . salt ,
177
178
} ;
178
179
179
- var cryptoHeader = 'keyid=p256dh;dh=' + urlBase64 . encode ( encrypted . localPublicKey ) ;
180
-
181
- if ( useCryptoKey ) {
182
- options . headers [ 'Crypto-Key' ] = cryptoHeader ;
183
- } else {
184
- options . headers [ 'Encryption-Key' ] = cryptoHeader ;
185
- }
186
- options . headers [ 'Content-Encoding' ] = encodingHeader ;
180
+ options . headers [ cryptoHeaderName ] = 'keyid=p256dh;dh=' + urlBase64 . encode ( encrypted . localPublicKey ) ;
187
181
}
188
182
189
183
var gcmPayload ;
@@ -210,7 +204,7 @@ function sendNotification(endpoint, params) {
210
204
options . headers [ 'Content-Length' ] = gcmPayload . length ;
211
205
}
212
206
213
- if ( vapid && ! isGCM && ( ! encrypted || useCryptoKey ) ) {
207
+ if ( vapid && ! isGCM && ( typeof payload === 'undefined' || 'Crypto-Key' in options . headers ) ) {
214
208
// VAPID isn't supported by GCM.
215
209
// We also can't use it when there's a payload on Firefox 45, because
216
210
// Firefox 45 uses the old standard with Encryption-Key.
0 commit comments