From 4a2ecd8607e577680b551e1f708dc6c2f5fa98d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADn?= Date: Tue, 3 Jun 2025 16:58:37 +0200 Subject: [PATCH 1/2] It was documented that a timeout could be set for webpushes, but there was no logic behind it. --- push_notifications/conf/app.py | 4 ++++ push_notifications/conf/legacy.py | 4 ++++ push_notifications/settings.py | 2 +- push_notifications/webpush.py | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/push_notifications/conf/app.py b/push_notifications/conf/app.py index a70aa1f5..bd4d5b8e 100644 --- a/push_notifications/conf/app.py +++ b/push_notifications/conf/app.py @@ -218,6 +218,7 @@ def _validate_wp_config(self, application_id, application_config): "EDGE": "https://wns2-par02p.notify.windows.com/w", "FIREFOX": "https://updates.push.services.mozilla.com/wpush/v2", }) + application_config.setdefault("ERROR_TIMEOUT", 1) def _validate_allowed_settings(self, application_id, application_config, allowed_settings): """Confirm only allowed settings are present.""" @@ -349,3 +350,6 @@ def get_wp_private_key(self, application_id=None): def get_wp_claims(self, application_id=None): return self._get_application_settings(application_id, "WP", "CLAIMS") + + def get_wp_error_timeout(self, application_id=None): + return self._get_application_settings(application_id, "WP", "ERROR_TIMEOUT") diff --git a/push_notifications/conf/legacy.py b/push_notifications/conf/legacy.py index 93a64cab..0118b5a7 100644 --- a/push_notifications/conf/legacy.py +++ b/push_notifications/conf/legacy.py @@ -128,3 +128,7 @@ def get_wp_private_key(self, application_id=None): def get_wp_claims(self, application_id=None): msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages" return self._get_application_settings(application_id, "WP_CLAIMS", msg) + + def get_wp_error_timeout(self, application_id=None): + msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to set a timeout" + return self._get_application_settings(application_id, "WP_ERROR_TIMEOUT", msg) diff --git a/push_notifications/settings.py b/push_notifications/settings.py index 5fba8b33..7044f55f 100644 --- a/push_notifications/settings.py +++ b/push_notifications/settings.py @@ -40,7 +40,7 @@ }) PUSH_NOTIFICATIONS_SETTINGS.setdefault("WP_PRIVATE_KEY", None) PUSH_NOTIFICATIONS_SETTINGS.setdefault("WP_CLAIMS", None) -PUSH_NOTIFICATIONS_SETTINGS.setdefault("WP_ERROR_TIMEOUT", None) +PUSH_NOTIFICATIONS_SETTINGS.setdefault("WP_ERROR_TIMEOUT", 1) # User model PUSH_NOTIFICATIONS_SETTINGS.setdefault("USER_MODEL", settings.AUTH_USER_MODEL) diff --git a/push_notifications/webpush.py b/push_notifications/webpush.py index de379431..0a938823 100644 --- a/push_notifications/webpush.py +++ b/push_notifications/webpush.py @@ -37,6 +37,7 @@ def webpush_send_message(device, message, **kwargs): data=message, vapid_private_key=get_manager().get_wp_private_key(device.application_id), vapid_claims=get_manager().get_wp_claims(device.application_id).copy(), + timeout=get_manager().get_wp_error_timeout(device.application_id), **kwargs ) if response.ok: From 50b02e99e9b1af422affcaa310ec674b46f18997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADn?= Date: Tue, 3 Jun 2025 17:16:16 +0200 Subject: [PATCH 2/2] Improve readme file --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 81650929..2ccf6f84 100644 --- a/README.rst +++ b/README.rst @@ -129,7 +129,7 @@ For WNS, you need both the ``WNS_PACKAGE_SECURITY_KEY`` and the ``WNS_SECRET_KEY - ``WP_PRIVATE_KEY``: Absolute path to your private certificate file: os.path.join(BASE_DIR, "private_key.pem") - ``WP_CLAIMS``: Dictionary with default value for the sub, (subject), sent to the webpush service, This would be used by the service if they needed to reach out to you (the sender). Could be a url or mailto e.g. {'sub': "mailto:development@example.com"}. -- ``WP_ERROR_TIMEOUT``: The timeout on WebPush POSTs. (Optional) +- ``WP_ERROR_TIMEOUT``: The timeout on WebPush POSTs. (Optional, default value is 1 second) For more information about how to configure WebPush, see `docs/WebPush `_.