Scrapy, a fast high-level web crawling & scraping framework for Python.
Allow overriding ClientContextFactory and enable SSL bug workarounds by default. refs #82
Daniel Graña2840865746a2
diff --git a/scrapy/core/downloader/handlers/http.py b/scrapy/core/downloader/handlers/http.pyindex 61391c626..ff0beb321 100644--- a/scrapy/core/downloader/handlers/http.py+++ b/scrapy/core/downloader/handlers/http.py@@ -8,10 +8,9 @@ from scrapy.conf import settingsfrom scrapy import optional_featuresssl_supported = 'ssl' in optional_features-if ssl_supported:- from twisted.internet.ssl import ClientContextFactoryHTTPClientFactory = load_object(settings['DOWNLOADER_HTTPCLIENTFACTORY'])+ClientContextFactory = load_object(settings['DOWNLOADER_CLIENTCONTEXTFACTORY'])class HttpDownloadHandler(object):diff --git a/scrapy/core/downloader/webclient.py b/scrapy/core/downloader/webclient.pyindex 6579475a9..c76593bd6 100644--- a/scrapy/core/downloader/webclient.py+++ b/scrapy/core/downloader/webclient.py@@ -9,6 +9,7 @@ from twisted.internet import deferfrom scrapy.http import Headersfrom scrapy.utils.httpobj import urlparse_cachedfrom scrapy.responsetypes import responsetypes+from scrapy import optional_featuresdef _parsed_url_args(parsed):@@ -135,3 +136,19 @@ class ScrapyHTTPClientFactory(HTTPClientFactory):def gotHeaders(self, headers):self.headers_time = time()self.response_headers = headers++++if 'ssl' in optional_features:+ from twisted.internet.ssl import ClientContextFactory+ from OpenSSL import SSL+else:+ ClientContextFactory = object+++class ScrapyClientContextFactory(ClientContextFactory):++ def getContext(self):+ ctx = ClientContextFactory.getContext(self)+ ctx.set_options(SSL.OP_ALL)+ return ctxdiff --git a/scrapy/settings/default_settings.py b/scrapy/settings/default_settings.pyindex 7e4363507..278ce8570 100644--- a/scrapy/settings/default_settings.py+++ b/scrapy/settings/default_settings.py@@ -64,6 +64,7 @@ DOWNLOAD_TIMEOUT = 180 # 3minsDOWNLOADER_DEBUG = FalseDOWNLOADER_HTTPCLIENTFACTORY = 'scrapy.core.downloader.webclient.ScrapyHTTPClientFactory'+DOWNLOADER_CLIENTCONTEXTFACTORY = 'scrapy.core.downloader.webclient.ScrapyClientContextFactory'DOWNLOADER_MIDDLEWARES = {}