Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ $defaultOptions = [
'urgency' => 'normal', // protocol defaults to "normal". (very-low, low, normal, or high)
'topic' => 'newEvent', // not defined by default. Max. 32 characters from the URL or filename-safe Base64 characters sets
'batchSize' => 200, // defaults to 1000
'contentType' => 'application/json', // defaults to "application/octet-stream"
];

// for every notification
Expand Down Expand Up @@ -235,6 +236,11 @@ In order to fix this, WebPush sends notifications in batches. The default size i
to decrease this number. Do this while instantiating WebPush or calling `setDefaultOptions`. Or, if you want to customize this for a specific flush, give
it as a parameter : `$webPush->flush($batchSize)`.

#### contentType

Sets the "Content-Type" header for HTTP requests with a non-empty payload sent to the push service.
Especially newer [Declarative push messages](https://www.w3.org/TR/push-api/#declarative-push-message) require a specific JSON payload, so this should be set to "application/json" in such cases.

### Server errors

You can see what the browser vendor's server sends back in case it encountered an error (push subscription expiration, wrong parameters...).
Expand Down
1 change: 1 addition & 0 deletions src/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function getOptions(array $defaultOptions = []): array
$options['TTL'] = array_key_exists('TTL', $options) ? $options['TTL'] : $defaultOptions['TTL'];
$options['urgency'] = array_key_exists('urgency', $options) ? $options['urgency'] : $defaultOptions['urgency'];
$options['topic'] = array_key_exists('topic', $options) ? $options['topic'] : $defaultOptions['topic'];
$options['contentType'] = array_key_exists('contentType', $options) ? $options['contentType'] : $defaultOptions['contentType'];

return $options;
}
Expand Down
3 changes: 2 additions & 1 deletion src/WebPush.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ protected function prepare(array $notifications): array
$localPublicKey = $encrypted['localPublicKey'];

$headers = [
'Content-Type' => 'application/octet-stream',
'Content-Type' => $options['contentType'],
'Content-Encoding' => $contentEncoding,
];

Expand Down Expand Up @@ -384,6 +384,7 @@ public function setDefaultOptions(array $defaultOptions): WebPush
$this->defaultOptions['topic'] = $defaultOptions['topic'] ?? null;
$this->defaultOptions['batchSize'] = $defaultOptions['batchSize'] ?? 1000;
$this->defaultOptions['requestConcurrency'] = $defaultOptions['requestConcurrency'] ?? 100;
$this->defaultOptions['contentType'] = $defaultOptions['contentType'] ?? 'application/octet-stream';


return $this;
Expand Down