bpo-25068: urllib.request.ProxyHandler now lowercases the dict keys (GH-13489)
(cherry picked from commit b761e3aed1
)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
This commit is contained in:
parent
bd2e7cc3af
commit
590ed09a5b
|
@ -1340,8 +1340,10 @@ class HandlerTests(unittest.TestCase):
|
|||
self.assertTrue(request.startswith(expected), repr(request))
|
||||
|
||||
def test_proxy(self):
|
||||
u = "proxy.example.com:3128"
|
||||
for d in dict(http=u), dict(HTTP=u):
|
||||
o = OpenerDirector()
|
||||
ph = urllib.request.ProxyHandler(dict(http="proxy.example.com:3128"))
|
||||
ph = urllib.request.ProxyHandler(d)
|
||||
o.add_handler(ph)
|
||||
meth_spec = [
|
||||
[("http_open", "return response")]
|
||||
|
@ -1351,8 +1353,7 @@ class HandlerTests(unittest.TestCase):
|
|||
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(req.host, u)
|
||||
self.assertEqual([(handlers[0], "http_open")],
|
||||
[tup[0:2] for tup in o.calls])
|
||||
|
||||
|
|
|
@ -800,6 +800,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))
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
:class:`urllib.request.ProxyHandler` now lowercases the keys of the passed
|
||||
dictionary.
|
Loading…
Reference in New Issue