Scrapy, a fast high-level web crawling & scraping framework for Python.
Deprecate the HTTPS proxy noconnect mode.
Andrey Rakhmatullin63546cbf3e02
diff --git a/scrapy/core/downloader/handlers/http11.py b/scrapy/core/downloader/handlers/http11.pyindex 7d917cb74..782eca89e 100644--- a/scrapy/core/downloader/handlers/http11.py+++ b/scrapy/core/downloader/handlers/http11.py@@ -16,6 +16,7 @@ from twisted.web.http import _DataLoss, PotentialDataLossfrom twisted.web.client import Agent, ResponseDone, HTTPConnectionPool, ResponseFailed, URIfrom twisted.internet.endpoints import TCP4ClientEndpoint+from scrapy.exceptions import ScrapyDeprecationWarningfrom scrapy.http import Headersfrom scrapy.responsetypes import responsetypesfrom scrapy.core.downloader.webclient import _parse@@ -285,6 +286,12 @@ class ScrapyAgent(object):scheme = _parse(request.url)[0]proxyHost = to_unicode(proxyHost)omitConnectTunnel = b'noconnect' in proxyParams+ if omitConnectTunnel:+ warnings.warn("Using HTTPS proxies in the noconnect mode is deprecated. "+ "If you use Crawlera, it doesn't require this mode anymore, "+ "so you should update scrapy-crawlera to 1.3.0+ "+ "and remove '?noconnect' from the Crawlera URL.",+ ScrapyDeprecationWarning)if scheme == b'https' and not omitConnectTunnel:proxyAuth = request.headers.get(b'Proxy-Authorization', None)proxyConf = (proxyHost, proxyPort, proxyAuth)diff --git a/tests/test_downloader_handlers.py b/tests/test_downloader_handlers.pyindex 60124b93f..45d4aa952 100644--- a/tests/test_downloader_handlers.py+++ b/tests/test_downloader_handlers.py@@ -687,16 +687,6 @@ class HttpProxyTestCase(unittest.TestCase):request = Request('http://example.com', meta={'proxy': http_proxy})return self.download_request(request, Spider('foo')).addCallback(_test)- def test_download_with_proxy_https_noconnect(self):- def _test(response):- self.assertEqual(response.status, 200)- self.assertEqual(response.url, request.url)- self.assertEqual(response.body, b'https://example.com')-- http_proxy = '%s?noconnect' % self.getURL('')- request = Request('https://example.com', meta={'proxy': http_proxy})- return self.download_request(request, Spider('foo')).addCallback(_test)-def test_download_without_proxy(self):def _test(response):self.assertEqual(response.status, 200)diff --git a/tests/test_proxy_connect.py b/tests/test_proxy_connect.pyindex 277455751..05d371b65 100644--- a/tests/test_proxy_connect.py+++ b/tests/test_proxy_connect.py@@ -108,32 +108,6 @@ class ProxyConnectTestCase(TestCase):echo = json.loads(crawler.spider.meta['responses'][0].text)self.assertTrue('Proxy-Authorization' not in echo['headers'])- # The noconnect mode isn't supported by the current mitmproxy, it returns- # "Invalid request scheme: https" as it doesn't seem to support full URLs in GET at all,- # and it's not clear what behavior is intended by Scrapy and by mitmproxy here.- # https://github.com/mitmproxy/mitmproxy/issues/848 may be related.- # The Scrapy noconnect mode was required, at least in the past, to work with Crawlera,- # and https://github.com/scrapy-plugins/scrapy-crawlera/pull/44 seems to be related.-- @pytest.mark.xfail(reason='mitmproxy gives an error for noconnect requests')- @defer.inlineCallbacks- def test_https_noconnect(self):- proxy = os.environ['https_proxy']- os.environ['https_proxy'] = proxy + '?noconnect'- crawler = get_crawler(SimpleSpider)- with LogCapture() as l:- yield crawler.crawl(self.mockserver.url("/status?n=200", is_secure=True))- self._assert_got_response_code(200, l)-- @pytest.mark.xfail(reason='mitmproxy gives an error for noconnect requests')- @defer.inlineCallbacks- def test_https_noconnect_auth_error(self):- os.environ['https_proxy'] = _wrong_credentials(os.environ['https_proxy']) + '?noconnect'- crawler = get_crawler(SimpleSpider)- with LogCapture() as l:- yield crawler.crawl(self.mockserver.url("/status?n=200", is_secure=True))- self._assert_got_response_code(407, l)-def _assert_got_response_code(self, code, log):print(log)self.assertEqual(str(log).count('Crawled (%d)' % code), 1)