Skip to content

Commit 097d5bc

Browse files
author
Gasper Zejn
committed
Separate network request from Web Push business logic, which allows using pywebpush with both blocking and nonblocking IO.
1 parent e743dc9 commit 097d5bc

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pywebpush/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ def send(self, data, headers={}, ttl=0, gcm_key=None, reg_id=None):
209209
headers['ttl'] = ttl
210210
# Additionally useful headers:
211211
# Authorization / Crypto-Key (VAPID headers)
212-
return requests.post(endpoint,
213-
data=encoded_data,
212+
return self._post(endpoint, encoded_data, headers)
213+
214+
def _post(self, url, data, headers):
215+
"""Make POST request on specified Web Push endpoint with given data
216+
and headers.
217+
218+
Subclass this class and override this method if you want to use any
219+
other networking library or interface and keep the business logic.
220+
"""
221+
return requests.post(url,
222+
data=data,
214223
headers=headers)

0 commit comments

Comments
 (0)