[feat] add close method for http agent
authordrebs <drebs@leap.se>
Wed, 8 Jul 2015 22:14:00 +0000 (19:14 -0300)
committerRuben Pollan <meskio@sindominio.net>
Wed, 22 Jul 2015 14:04:22 +0000 (10:04 -0400)
The ability to close cached connections is needed in order to have a clean
reactor when the program ends.

src/leap/common/http.py

index d4a214c..8d22f2c 100644 (file)
@@ -80,6 +80,7 @@ class HTTPClient(object):
 
         policy = get_compatible_ssl_context_factory(cert_file)
 
+        self._pool = pool
         self._agent = Agent(
             reactor,
             policy,
@@ -110,6 +111,12 @@ class HTTPClient(object):
         d.addCallback(readBody)
         return d
 
+    def close(self):
+        """
+        Close any cached connections.
+        """
+        self._pool.closeCachedConnections()
+
     class StringBodyProducer(object):
         """
         A producer that writes the body of a request to a consumer.