Skip to content

Commit 347e8d0

Browse files
committed
Added support for timeouts in messaging module
1 parent 176ef5f commit 347e8d0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

firebase_admin/messaging.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ def __init__(self, app):
741741
'GCLOUD_PROJECT environment variable.')
742742
self._fcm_url = _MessagingService.FCM_URL.format(project_id)
743743
self._client = _http_client.JsonHttpClient(credential=app.credential.get_credential())
744+
self._timeout = app.options.get('httpTimeout')
744745

745746
@classmethod
746747
def encode_message(cls, message):
@@ -753,7 +754,7 @@ def send(self, message, dry_run=False):
753754
if dry_run:
754755
data['validate_only'] = True
755756
try:
756-
resp = self._client.body('post', url=self._fcm_url, json=data)
757+
resp = self._client.body('post', url=self._fcm_url, json=data, timeout=self._timeout)
757758
except requests.exceptions.RequestException as error:
758759
if error.response is not None:
759760
self._handle_fcm_error(error)
@@ -784,7 +785,12 @@ def make_topic_management_request(self, tokens, topic, operation):
784785
url = '{0}/{1}'.format(_MessagingService.IID_URL, operation)
785786
try:
786787
resp = self._client.body(
787-
'post', url=url, json=data, headers=_MessagingService.IID_HEADERS)
788+
'post',
789+
url=url,
790+
json=data,
791+
headers=_MessagingService.IID_HEADERS,
792+
timeout=self._timeout
793+
)
788794
except requests.exceptions.RequestException as error:
789795
if error.response is not None:
790796
self._handle_iid_error(error)

0 commit comments

Comments
 (0)