downloadWithProgress: support https with connectSSL
authorAthanasios Oikonomou <athoik@gmail.com>
Thu, 23 Apr 2015 05:24:17 +0000 (08:24 +0300)
committerlittlesat <littlesat99@yahoo.com>
Thu, 23 Apr 2015 08:51:56 +0000 (10:51 +0200)
Downloading https page fails with "Connection was closed cleanly"
because downloadWithProgress uses connectTCP instead of connectSSL.

Using connectSSL for https solves the problem.

Signed-off-by: littlesat <littlesat99@yahoo.com>

lib/python/Tools/Downloader.py

index fe86eac..e67aaed 100644 (file)
@@ -43,7 +43,13 @@ class downloadWithProgress:
                host = parsed.hostname
                port = parsed.port or (443 if scheme == 'https' else 80)
                self.factory = HTTPProgressDownloader(url, outputfile, *args, **kwargs)
-               self.connection = reactor.connectTCP(host, port, self.factory)
+               if scheme == 'https':
+                       from twisted.internet import ssl
+                       if contextFactory is None:
+                               contextFactory = ssl.ClientContextFactory()
+                       self.connection = reactor.connectSSL(host, port, self.factory, contextFactory)
+               else:
+                       self.connection = reactor.connectTCP(host, port, self.factory)
 
        def start(self):
                return self.factory.deferred