check for unparseable no_proxy values

This commit is contained in:
drs-11 2020-09-05 21:32:05 +05:30
parent c1cc3f2f42
commit 959222df7e
2 changed files with 10 additions and 1 deletions

View File

@ -13,7 +13,12 @@ class HttpProxyMiddleware:
self.auth_encoding = auth_encoding
self.proxies = {}
for type_, url in getproxies().items():
self.proxies[type_] = self._get_proxy(url, type_)
try:
self.proxies[type_] = self._get_proxy(url, type_)
# some values such as '/var/run/docker.sock' can't be parsed
# by _parse_proxy and as such should be skipped
except ValueError:
continue
@classmethod
def from_crawler(cls, crawler):

View File

@ -123,7 +123,11 @@ class TestHttpProxyMiddleware(TestCase):
def test_no_proxy(self):
os.environ['http_proxy'] = 'https://proxy.for.http:3128'
os.environ['no_proxy'] = '/var/run/docker.sock'
mw = HttpProxyMiddleware()
# '/var/run/docker.sock' may be used by the user for
# no_proxy value but is not parseable and should be skipped
assert 'no' not in mw.proxies
os.environ['no_proxy'] = '*'
req = Request('http://noproxy.com')