diff --git a/README.md b/README.md index e61d4b6..0af0f48 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ $notifications = [ 'endpoint' => 'https://example.com/other/endpoint/of/another/vendor/abcdef...', 'publicKey' => '(stringOf88Chars)', 'authToken' => '(stringOf24Chars)', - 'contentEncoding' => 'aesgcm', // one of PushManager.supportedContentEncodings + 'contentEncoding' => 'aesgcm', // encoding supported by both the browser and this library ]), 'payload' => '{"message":"test"}', ] @@ -130,6 +130,21 @@ $report = $webPush->sendOneNotification( ); ``` +#### Content encoding negotiation + +Browsers can expose supported content encodings through `PushManager.supportedContentEncodings`. The library exposes its supported encodings through the public `ContentEncoding` enum, so applications can negotiate without duplicating a hard-coded list: + +```php +use Minishlink\WebPush\ContentEncoding; + +$librarySupportedContentEncodings = array_map( + static fn (ContentEncoding $encoding): string => $encoding->value, + ContentEncoding::cases(), +); +``` + +Use this list to validate or negotiate the browser-provided encodings before creating the `Subscription`, then pass the selected value as `contentEncoding`. If there is no overlap, treat the subscription as unsupported instead of guessing an encoding. + ### Authentication (VAPID) Browsers need to verify your identity. A standard called VAPID can authenticate you for all browsers based on [RFC8292](https://www.rfc-editor.org/rfc/rfc8292).