summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2019-09-13 14:07:07 (GMT)
committerStéphane Wirtel <stephane@wirtel.be>2019-09-13 14:07:07 (GMT)
commitb761e3aed1fbada4572a776f6a0d3c4be491d595 (patch)
tree86d21eb690fd5f7cf43a86e0c3953c07de1e0e92 /Lib
parent693aa80a434590ea7dcd35c000209e53d01b9425 (diff)
downloadcpython-b761e3aed1fbada4572a776f6a0d3c4be491d595.zip
cpython-b761e3aed1fbada4572a776f6a0d3c4be491d595.tar.gz
cpython-b761e3aed1fbada4572a776f6a0d3c4be491d595.tar.bz2
bpo-25068: urllib.request.ProxyHandler now lowercases the dict keys (GH-13489)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_urllib2.py31
-rw-r--r--Lib/urllib/request.py1
2 files changed, 17 insertions, 15 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index c228fa7..186a967 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1342,21 +1342,22 @@ class HandlerTests(unittest.TestCase):
self.assertTrue(request.startswith(expected), repr(request))
def test_proxy(self):
- o = OpenerDirector()
- ph = urllib.request.ProxyHandler(dict(http="proxy.example.com:3128"))
- o.add_handler(ph)
- meth_spec = [
- [("http_open", "return response")]
- ]
- handlers = add_ordered_mock_handlers(o, meth_spec)
-
- req = Request("http://acme.example.com/")
- self.assertEqual(req.host, "acme.example.com")
- o.open(req)
- self.assertEqual(req.host, "proxy.example.com:3128")
-
- self.assertEqual([(handlers[0], "http_open")],
- [tup[0:2] for tup in o.calls])
+ u = "proxy.example.com:3128"
+ for d in dict(http=u), dict(HTTP=u):
+ o = OpenerDirector()
+ ph = urllib.request.ProxyHandler(d)
+ o.add_handler(ph)
+ meth_spec = [
+ [("http_open", "return response")]
+ ]
+ handlers = add_ordered_mock_handlers(o, meth_spec)
+
+ req = Request("http://acme.example.com/")
+ self.assertEqual(req.host, "acme.example.com")
+ o.open(req)
+ self.assertEqual(req.host, u)
+ self.assertEqual([(handlers[0], "http_open")],
+ [tup[0:2] for tup in o.calls])
def test_proxy_no_proxy(self):
os.environ['no_proxy'] = 'python.org'
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 267a90d..721c152 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -792,6 +792,7 @@ class ProxyHandler(BaseHandler):
assert hasattr(proxies, 'keys'), "proxies must be a mapping"
self.proxies = proxies
for type, url in proxies.items():
+ type = type.lower()
setattr(self, '%s_open' % type,
lambda r, proxy=url, type=type, meth=self.proxy_open:
meth(r, proxy, type))