mirror of https://github.com/python/cpython.git
Change all header strings to be as if they were capitalize()'ed. Also call
capitalize in AbstractHTTPHandler before inserting headers into HTTP instance. Closes bug #649742, again.
This commit is contained in:
parent
5ecd6c4db2
commit
783eaf4774
|
@ -254,7 +254,7 @@ def add_header(self, key, val):
|
|||
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 = {}
|
||||
|
@ -507,7 +507,7 @@ def proxy_open(self, req, proxy, type):
|
|||
user, password = user_pass.split(':', 1)
|
||||
user_pass = base64.encodestring('%s:%s' % (unquote(user),
|
||||
unquote(password)))
|
||||
req.add_header('Proxy-Authorization', 'Basic ' + user_pass)
|
||||
req.add_header('Proxy-authorization', 'Basic ' + user_pass)
|
||||
host = unquote(host)
|
||||
req.set_proxy(host, type)
|
||||
if orig_type == type:
|
||||
|
@ -666,7 +666,7 @@ def http_error_401(self, req, fp, code, msg, headers):
|
|||
|
||||
class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
|
||||
|
||||
auth_header = 'Proxy-Authorization'
|
||||
auth_header = 'Proxy-authorization'
|
||||
|
||||
def http_error_407(self, req, fp, code, msg, headers):
|
||||
host = req.get_host()
|
||||
|
@ -818,10 +818,10 @@ def do_open(self, http_class, req):
|
|||
scheme, sel = splittype(req.get_selector())
|
||||
sel_host, sel_path = splithost(sel)
|
||||
h.putheader('Host', sel_host or host)
|
||||
for args in self.parent.addheaders:
|
||||
name, value = args
|
||||
for name, value in self.parent.addheaders:
|
||||
name = name.capitalize()
|
||||
if name not in req.headers:
|
||||
h.putheader(*args)
|
||||
h.putheader(name, value)
|
||||
for k, v in req.headers.items():
|
||||
h.putheader(k, v)
|
||||
# httplib will attempt to connect() here. be prepared
|
||||
|
@ -943,7 +943,7 @@ def open_local_file(self, req):
|
|||
modified = rfc822.formatdate(stats.st_mtime)
|
||||
mtype = mimetypes.guess_type(file)[0]
|
||||
headers = mimetools.Message(StringIO(
|
||||
'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
|
||||
'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
|
||||
(mtype or 'text/plain', size, modified)))
|
||||
if host:
|
||||
host, port = splitport(host)
|
||||
|
@ -985,9 +985,9 @@ def ftp_open(self, req):
|
|||
headers = ""
|
||||
mtype = mimetypes.guess_type(req.get_full_url())[0]
|
||||
if mtype:
|
||||
headers += "Content-Type: %s\n" % mtype
|
||||
headers += "Content-type: %s\n" % mtype
|
||||
if retrlen is not None and retrlen >= 0:
|
||||
headers += "Content-Length: %d\n" % retrlen
|
||||
headers += "Content-length: %d\n" % retrlen
|
||||
sf = StringIO(headers)
|
||||
headers = mimetools.Message(sf)
|
||||
return addinfourl(fp, headers, req.get_full_url())
|
||||
|
|
Loading…
Reference in New Issue