Fix for SF bug #599836: Don't duplicate headers.

If the request object has a header, it should override the default
header provided by the OpenerDirector.
This commit is contained in:
Jeremy Hylton 2002-10-11 17:26:46 +00:00
parent a0f453b2b1
commit 96f1129de8

View File

@ -247,7 +247,7 @@ class Request:
class OpenerDirector:
def __init__(self):
server_version = "Python-urllib/%s" % __version__
self.addheaders = [('User-agent', server_version)]
self.addheaders = [('User-Agent', server_version)]
# manage the individual handlers
self.handlers = []
self.handle_open = {}
@ -771,7 +771,8 @@ class AbstractHTTPHandler(BaseHandler):
sel_host, sel_path = splithost(sel)
h.putheader('Host', sel_host or host)
for args in self.parent.addheaders:
h.putheader(*args)
if name not in req.headers:
h.putheader(*args)
for k, v in req.headers.items():
h.putheader(k, v)
h.endheaders()