From 17e47ab64746c6eb90656278ae75ee5dc87b88dd Mon Sep 17 00:00:00 2001 From: Roman Ackermann Date: Thu, 13 Nov 2025 16:46:22 +0100 Subject: [PATCH 1/3] Added contentType option to Notification --- src/Notification.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Notification.php b/src/Notification.php index a924fbb..38f69b0 100644 --- a/src/Notification.php +++ b/src/Notification.php @@ -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; } From 21955f920cf1ee69ebb4dbc8e6e3b4048ec3561b Mon Sep 17 00:00:00 2001 From: Roman Ackermann Date: Thu, 13 Nov 2025 16:48:00 +0100 Subject: [PATCH 2/3] Added contentType option to WebPush --- src/WebPush.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/WebPush.php b/src/WebPush.php index e470b6e..5e37f54 100644 --- a/src/WebPush.php +++ b/src/WebPush.php @@ -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, ]; @@ -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; From f0892c1e011f2da12a89da758eaf86c207e5e04e Mon Sep 17 00:00:00 2001 From: Roman Ackermann Date: Thu, 13 Nov 2025 16:49:32 +0100 Subject: [PATCH 3/3] Updated README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 978e6b2..c849a1e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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...).