mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Merged revisions 85025 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r85025 | senthil.kumaran | 2010-09-27 06:56:03 +0530 (Mon, 27 Sep 2010) | 6 lines 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. ........
This commit is contained in:
parent
658f629c86
commit
176c73df0f
2 changed files with 16 additions and 2 deletions
|
@ -172,6 +172,18 @@ class OtherNetworkTests(unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
res.close()
|
res.close()
|
||||||
|
|
||||||
|
def test_custom_headers(self):
|
||||||
|
url = "http://www.example.com"
|
||||||
|
opener = urllib2.build_opener()
|
||||||
|
request = urllib2.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):
|
def _test_urls(self, urls, handlers, retry=True):
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
|
|
@ -1127,8 +1127,10 @@ class AbstractHTTPHandler(BaseHandler):
|
||||||
h = http_class(host, timeout=req.timeout) # will parse host:port
|
h = http_class(host, timeout=req.timeout) # will parse host:port
|
||||||
h.set_debuglevel(self._debuglevel)
|
h.set_debuglevel(self._debuglevel)
|
||||||
|
|
||||||
headers = dict(req.headers)
|
headers = dict(req.unredirected_hdrs)
|
||||||
headers.update(req.unredirected_hdrs)
|
headers.update(dict((k, v) for k, v in req.headers.items()
|
||||||
|
if k not in headers))
|
||||||
|
|
||||||
# We want to make an HTTP/1.1 request, but the addinfourl
|
# We want to make an HTTP/1.1 request, but the addinfourl
|
||||||
# class isn't prepared to deal with a persistent connection.
|
# class isn't prepared to deal with a persistent connection.
|
||||||
# It will try to read all remaining data from the socket,
|
# It will try to read all remaining data from the socket,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue