Skip to content

Commit e651a89

Browse files
committed
Don't include vapid headers if there are no content encoding
1 parent 6edbcc6 commit e651a89

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/WebPush.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private function prepare(array $notifications): array
263263
}
264264
}
265265
// if VAPID (GCM doesn't support it but FCM does)
266-
elseif (array_key_exists('VAPID', $auth)) {
266+
elseif (array_key_exists('VAPID', $auth) && $contentEncoding) {
267267
$audience = parse_url($endpoint, PHP_URL_SCHEME).'://'.parse_url($endpoint, PHP_URL_HOST);
268268
if (!parse_url($audience)) {
269269
throw new \ErrorException('Audience "'.$audience.'"" could not be generated.');
@@ -373,12 +373,12 @@ public function countPendingNotifications(): int
373373

374374
/**
375375
* @param string $audience
376-
* @param string|null $contentEncoding
376+
* @param string $contentEncoding
377377
* @param array $vapid
378378
* @return array
379379
* @throws \ErrorException
380380
*/
381-
private function getVAPIDHeaders(string $audience, ?string $contentEncoding, array $vapid)
381+
private function getVAPIDHeaders(string $audience, string $contentEncoding, array $vapid)
382382
{
383383
$vapidHeaders = null;
384384

@@ -391,10 +391,6 @@ private function getVAPIDHeaders(string $audience, ?string $contentEncoding, arr
391391
}
392392

393393
if (!$vapidHeaders) {
394-
if (!$contentEncoding) {
395-
throw new \ErrorException('Subscription should have a content encoding');
396-
}
397-
398394
$vapidHeaders = VAPID::getVapidHeaders($audience, $vapid['subject'], $vapid['publicKey'], $vapid['privateKey'], $contentEncoding);
399395
}
400396

0 commit comments

Comments
 (0)