diff options
author | Senthil Kumaran <orsenthil@gmail.com> | 2010-09-27 01:26:03 (GMT) |
---|---|---|
committer | Senthil Kumaran <orsenthil@gmail.com> | 2010-09-27 01:26:03 (GMT) |
commit | 42ef4b1f4c8f07357f7c4e9cb8470f57365b0ffa (patch) | |
tree | 1d2fa130f808aaa59e11354bf1445cc9d12348c3 /Lib/test/test_urllib2net.py | |
parent | cb159881148812b6a842748ecc8c820402e9df65 (diff) | |
download | cpython-42ef4b1f4c8f07357f7c4e9cb8470f57365b0ffa.zip cpython-42ef4b1f4c8f07357f7c4e9cb8470f57365b0ffa.tar.gz cpython-42ef4b1f4c8f07357f7c4e9cb8470f57365b0ffa.tar.bz2 |
Fix Issue1595365 - Adding the req.headers after the un-redirect headers have
been added. This helps in accidental overwritting of User-Agent header to
default value. To preserve the old behavior, only headers not in unredirected
headers will be updated.
Diffstat (limited to 'Lib/test/test_urllib2net.py')
-rw-r--r-- | Lib/test/test_urllib2net.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py index 8b9435a..a4af01a 100644 --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -156,6 +156,18 @@ class OtherNetworkTests(unittest.TestCase): self.assertEqual(res.geturl(), "http://docs.python.org/glossary.html") + def test_custom_headers(self): + url = "http://www.example.com" + opener = urllib.request.build_opener() + request = urllib.request.Request(url) + self.assertFalse(request.header_items()) + opener.open(request) + self.assertTrue(request.header_items()) + self.assertTrue(request.has_header('User-agent')) + request.add_header('User-Agent','Test-Agent') + opener.open(request) + self.assertEqual(request.get_header('User-agent'),'Test-Agent') + def _test_urls(self, urls, handlers, retry=True): import time import logging |