8000 Add support for session pooling at the Client layer. Set default to T… · chiewxia/twilio-python@2f0f62d · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f0f62d

Browse files
pshaftonjingming
authored andcommitted
Add support for session pooling at the Client layer. Set default to True (twilio#375)
1 parent 6620134 commit 2f0f62d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

twilio/http/http_client.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ class TwilioHttpClient(HttpClient):
88
"""
99
General purpose HTTP Client for interacting with the Twilio API
1010
"""
11+
def __init__(self, connection_pool=True):
12+
if connection_pool:
13+
self.session = Session()
14+
self.session.verify = get_cert_file()
15+
else:
16+
self.session = None
17+
1118
def request(self, method, url, params=None, data=None, headers=None, auth=None, timeout=None,
1219
allow_redirects=False):
1320
"""
@@ -26,8 +33,10 @@ def request(self, method, url, params=None, data=None, headers=None, auth=None,
2633
:return: An http response
2734
:rtype: A :class:`Response <twilio.rest.http.response.Response>` object
2835
"""
29-
session = Session()
30-
session.verify = get_cert_file()
36+
session = self.session
37+
if session is None:
38+
session = Session()
39+
session.verify = get_cert_file()
3140

3241
request = Request(method.upper(), url, params=params, data=data, headers=headers, auth=auth)
3342

0 commit comments

Comments
 (0)
0