@@ -71,6 +71,8 @@ class Connection(AioRunMixin):
71
71
- `blocking`: Whether to use a blocking API, without the need
72
72
for an explicit event loop.
73
73
- `session`: An optional :class:`aiohttp.ClientSession`.
74
+ - `session_kwargs`: Additional key value arguments passed to the
75
+ client session on each call to `get` and `post`.
74
76
"""
75
77
async_functions = {
76
78
'__exit__' ,
@@ -100,10 +102,11 @@ class Connection(AioRunMixin):
100
102
def __init__ (
101
103
self , identity , secret ,
102
104
key = None , key_file = None ,
103
- blocking = False , session = None ,
105
+ blocking = False , session = None , session_kwargs = None ,
104
106
):
105
107
super ().__init__ (blocking = blocking )
106
108
self ._session = session if session is not None else aiohttp .ClientSession ()
109
+ self ._session_kwargs = session_kwargs if session_kwargs is not None else {}
107
110
self ._key = None
108
111
self ._key_file = None
109
112
self .id = identity
@@ -307,12 +310,13 @@ async def _get(self, *args, **kwargs):
307
310
308
311
Return a :class:`aiohttp.ClientResponse` instance.
309
312
"""
313
+ kwargs = {** self ._session_kwargs , ** kwargs }
310
314
kwargs .setdefault ('params' , {})
311
315
kwargs ['params' ].setdefault ('from' , self .id )
312
316
kwargs ['params' ].setdefault ('secret' , self .secret )
313
317
return await self ._session .get (* args , ** kwargs )
314
318
315
- async def _send (self , url , data ):
319
+ async def _send (self , url , data , ** kwargs ):
316
320
"""
317
321
Send a message.
318
322
@@ -327,13 +331,14 @@ async def _send(self, url, data):
327
331
data .setdefault ('secret' , self .secret )
328
332
329
333
# Send message
330
- response = await self ._session .post (url , data = data )
334
+ kwargs = {** self ._session_kwargs , ** kwargs }
335
+ response = await self ._session .post (url , data = data , ** kwargs )
331
336
if response .status == 200 :
332
337
return await response .text ()
333
338
else :
334
339
await raise_server_error (response , MessageServerError )
335
340
336
- async def _upload (self , url , data ):
341
+ async def _upload (self , url , data , ** kwargs ):
337
342
"""
338
343
Upload a blob.
339
344
@@ -349,7 +354,8 @@ async def _upload(self, url, data):
349
354
files = {'blob' : data }
350
355
351
356
# Send message
352
- response = await self ._session .post (url , params = params , data = files )
357
+ kwargs = {** self ._session_kwargs , ** kwargs }
358
+ response = await self ._session .post (url , params = params , data = files , ** kwargs )
353
359
if response .status == 200 :
354
360
return await response .text ()
355
361
else :
0 commit comments