@@ -95,7 +95,7 @@ class WebPusher:
95
95
"aes128gcm" # draft-httpbis-encryption-encoding-04
96
96
]
97
97
98
- def __init__ (self , subscription_info ):
98
+ def __init__ (self , subscription_info , requests_session = None ):
99
99
"""Initialize using the info provided by the client PushSubscription
100
100
object (See
101
101
https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe)
@@ -104,7 +104,16 @@ def __init__(self, subscription_info):
104
104
the client.
105
105
:type subscription_info: dict
106
106
107
+ :param requests_session: a requests.Session object to optimize requests
108
+ to the same client.
109
+ :type requests_session: requests.Session
110
+
107
111
"""
112
+ if requests_session is None :
113
+ self .requests_method = requests
114
+ else :
115
+ self .requests_method = requests_session
116
+
108
117
if 'endpoint' not in subscription_info :
109
118
raise WebPushException ("subscription_info missing endpoint URL" )
110
119
self .subscription_info = subscription_info
@@ -285,10 +294,10 @@ def send(self, data=None, headers=None, ttl=0, gcm_key=None, reg_id=None,
285
294
# Authorization / Crypto-Key (VAPID headers)
286
295
if curl :
287
296
return self .as_curl (endpoint , encoded_data , headers )
288
- return requests .post (endpoint ,
289
- data = encoded_data ,
290
- headers = headers ,
291
- timeout = timeout )
297
+ return self . requests_method .post (endpoint ,
298
+ data = encoded_data ,
299
+ headers = headers ,
300
+ timeout = timeout )
292
301
293
302
294
303
def webpush (subscription_info ,
0 commit comments