diff options
author | Victor Shyba <victor.shyba@gmail.com> | 2015-05-27 17:19:13 -0300 |
---|---|---|
committer | Victor Shyba <victor.shyba@gmail.com> | 2015-06-02 19:28:02 -0300 |
commit | bf18c2bc6e3f533187281a3b31febd37ef22f8c0 (patch) | |
tree | 37041b527b6be4acddcad4843ffc654546c2c414 /src/leap/common/http.py | |
parent | c071c69e1b5a0d897674a1f7adc6ff32f19400ff (diff) |
[feat] Make it optional to have a dedicated pool
As @meskio pointed out, some cases could need a dedicated pool with
different parameters.
This is a suggested implementation where the pool is reused by default,
creating a dedicated one just if needed/asked. This way we ensure that
resources are under control and special cases are still handled.
Diffstat (limited to 'src/leap/common/http.py')
-rw-r--r-- | src/leap/common/http.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/leap/common/http.py b/src/leap/common/http.py index 1dc5642..1e384e5 100644 --- a/src/leap/common/http.py +++ b/src/leap/common/http.py @@ -44,13 +44,21 @@ from twisted.web.http_headers import Headers from twisted.web.iweb import IBodyProducer +def createPool(maxPersistentPerHost=10, persistent=True): + pool = HTTPConnectionPool(reactor, persistent) + pool.maxPersistentPerHost = maxPersistentPerHost + return pool + +_pool = createPool() + + class HTTPClient(object): """ HTTP client done the twisted way, with a main focus on pinning the SSL certificate. """ - def __init__(self, cert_file=None): + def __init__(self, cert_file=None, pool=_pool): """ Init the HTTP client @@ -58,15 +66,13 @@ class HTTPClient(object): system's CAs will be used. :type cert_file: str """ - self._pool = HTTPConnectionPool(reactor, persistent=True) - self._pool.maxPersistentPerHost = 10 policy = get_compatible_ssl_context_factory(cert_file) self._agent = Agent( reactor, policy, - pool=self._pool) + pool=pool) def request(self, url, method='GET', body=None, headers={}): """ |