@@ -95,7 +95,7 @@ class WebPusher:
9595 "aes128gcm" # draft-httpbis-encryption-encoding-04
9696 ]
9797
98- def __init__ (self , subscription_info ):
98+ def __init__ (self , subscription_info , requests_session = None ):
9999 """Initialize using the info provided by the client PushSubscription
100100 object (See
101101 https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe)
@@ -104,7 +104,16 @@ def __init__(self, subscription_info):
104104 the client.
105105 :type subscription_info: dict
106106
107+ :param requests_session: a requests.Session object to optimize requests
108+ to the same client.
109+ :type requests_session: requests.Session
110+
107111 """
112+ if requests_session is None :
113+ self .requests_method = requests
114+ else :
115+ self .requests_method = requests_session
116+
108117 if 'endpoint' not in subscription_info :
109118 raise WebPushException ("subscription_info missing endpoint URL" )
110119 self .subscription_info = subscription_info
@@ -285,10 +294,10 @@ def send(self, data=None, headers=None, ttl=0, gcm_key=None, reg_id=None,
285294 # Authorization / Crypto-Key (VAPID headers)
286295 if curl :
287296 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 )
292301
293302
294303def webpush (subscription_info ,
0 commit comments