Skip to content

Commit 4919ec1

Browse files
kilgoretrout1985jrconlin
authored andcommitted
Select legacy GCM or actual FCM endpoint for send based on the gcm_key (#110)
* Select legacy GCM or actual FCM endpoint for send based on the key provided. * Fixed flake8 issue
1 parent 051e157 commit 4919ec1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pywebpush/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,13 @@ def send(self, data=None, headers=None, ttl=0, gcm_key=None, reg_id=None,
308308
'content-encoding': content_encoding,
309309
})
310310
if gcm_key:
311-
endpoint = 'https://android.googleapis.com/gcm/send'
311+
# guess if it is a legacy GCM project key or actual FCM key
312+
# gcm keys are all about 40 chars (use 100 for confidence),
313+
# fcm keys are 153-175 chars
314+
if len(gcm_key) < 100:
315+
endpoint = 'https://android.googleapis.com/gcm/send'
316+
else:
317+
endpoint = 'https://fcm.googleapis.com/fcm/send'
312318
reg_ids = []
313319
if not reg_id:
314320
reg_id = self.subscription_info['endpoint'].rsplit('/', 1)[-1]

0 commit comments

Comments
 (0)