mirror of https://github.com/scrapy/scrapy.git
support empty password for http_proxy config
This commit is contained in:
parent
38e5bfb61c
commit
eb8fed4ecd
|
|
@ -25,7 +25,7 @@ class HttpProxyMiddleware(object):
|
|||
proxy_type, user, password, hostport = _parse_proxy(url)
|
||||
proxy_url = urlunparse((proxy_type or orig_type, hostport, '', '', '', ''))
|
||||
|
||||
if user and password:
|
||||
if user:
|
||||
user_pass = '%s:%s' % (unquote(user), unquote(password))
|
||||
creds = base64.b64encode(user_pass).strip()
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -54,6 +54,14 @@ class TestDefaultHeadersMiddleware(TestCase):
|
|||
self.assertEquals(req.meta, {'proxy': 'https://proxy:3128'})
|
||||
self.assertEquals(req.headers.get('Proxy-Authorization'), 'Basic dXNlcjpwYXNz')
|
||||
|
||||
def test_proxy_auth_empty_passwd(self):
|
||||
os.environ['http_proxy'] = 'https://user:@proxy:3128'
|
||||
mw = HttpProxyMiddleware()
|
||||
req = Request('http://scrapytest.org')
|
||||
assert mw.process_request(req, spider) is None
|
||||
self.assertEquals(req.meta, {'proxy': 'https://proxy:3128'})
|
||||
self.assertEquals(req.headers.get('Proxy-Authorization'), 'Basic dXNlcjo=')
|
||||
|
||||
def test_proxy_already_seted(self):
|
||||
os.environ['http_proxy'] = http_proxy = 'https://proxy.for.http:3128'
|
||||
mw = HttpProxyMiddleware()
|
||||
|
|
|
|||
Loading…
Reference in New Issue