Skip to content

Commit

Permalink
Don't include vapid headers if there are no content encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Minishlink committed Feb 23, 2019
1 parent 6edbcc6 commit e651a89
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/WebPush.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private function prepare(array $notifications): array
}
}
// if VAPID (GCM doesn't support it but FCM does)
elseif (array_key_exists('VAPID', $auth)) {
elseif (array_key_exists('VAPID', $auth) && $contentEncoding) {
$audience = parse_url($endpoint, PHP_URL_SCHEME).'://'.parse_url($endpoint, PHP_URL_HOST);
if (!parse_url($audience)) {
throw new \ErrorException('Audience "'.$audience.'"" could not be generated.');
Expand Down Expand Up @@ -373,12 +373,12 @@ public function countPendingNotifications(): int

/**
* @param string $audience
* @param string|null $contentEncoding
* @param string $contentEncoding
* @param array $vapid
* @return array
* @throws \ErrorException
*/
private function getVAPIDHeaders(string $audience, ?string $contentEncoding, array $vapid)
private function getVAPIDHeaders(string $audience, string $contentEncoding, array $vapid)
{
$vapidHeaders = null;

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

if (!$vapidHeaders) {
if (!$contentEncoding) {
throw new \ErrorException('Subscription should have a content encoding');
}

$vapidHeaders = VAPID::getVapidHeaders($audience, $vapid['subject'], $vapid['publicKey'], $vapid['privateKey'], $contentEncoding);
}

Expand Down

0 comments on commit e651a89

Please sign in to comment.