summaryrefslogtreecommitdiffstats
path: root/Lib/urllib2.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-03-28 12:40:24 (GMT)
committerGeorg Brandl <georg@python.org>2006-03-28 12:40:24 (GMT)
commitf1349cd05d31ba0a925d9931a7c437a9650c6488 (patch)
tree1c104179ce784202c1d3cdfdef34d8680ecfc5c6 /Lib/urllib2.py
parent240ec6b9efc2d9d9a23ee76383051acc2df9e074 (diff)
downloadcpython-f1349cd05d31ba0a925d9931a7c437a9650c6488.zip
cpython-f1349cd05d31ba0a925d9931a7c437a9650c6488.tar.gz
cpython-f1349cd05d31ba0a925d9931a7c437a9650c6488.tar.bz2
Bug #1459963: urllib2 now normalizes HTTP header names correctly
with title().
Diffstat (limited to 'Lib/urllib2.py')
-rw-r--r--Lib/urllib2.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 0434a51..bc6ee4b 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -254,11 +254,11 @@ class Request:
def add_header(self, key, val):
# useful for something like authentication
- self.headers[key.capitalize()] = val
+ self.headers[key.title()] = val
def add_unredirected_header(self, key, val):
# will not be added to a redirected request
- self.unredirected_hdrs[key.capitalize()] = val
+ self.unredirected_hdrs[key.title()] = val
def has_header(self, header_name):
return (header_name in self.headers or
@@ -277,7 +277,7 @@ class Request:
class OpenerDirector:
def __init__(self):
client_version = "Python-urllib/%s" % __version__
- self.addheaders = [('User-agent', client_version)]
+ self.addheaders = [('User-Agent', client_version)]
# manage the individual handlers
self.handlers = []
self.handle_open = {}
@@ -592,7 +592,7 @@ class ProxyHandler(BaseHandler):
user, password = user_pass.split(':', 1)
user_pass = base64.encodestring('%s:%s' % (unquote(user),
unquote(password))).strip()
- 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:
@@ -755,7 +755,7 @@ class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
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()
@@ -955,20 +955,20 @@ class AbstractHTTPHandler(BaseHandler):
if request.has_data(): # POST
data = request.get_data()
- if not request.has_header('Content-type'):
+ if not request.has_header('Content-Type'):
request.add_unredirected_header(
- 'Content-type',
+ 'Content-Type',
'application/x-www-form-urlencoded')
- if not request.has_header('Content-length'):
+ if not request.has_header('Content-Length'):
request.add_unredirected_header(
- 'Content-length', '%d' % len(data))
+ 'Content-Length', '%d' % len(data))
scheme, sel = splittype(request.get_selector())
sel_host, sel_path = splithost(sel)
if not request.has_header('Host'):
request.add_unredirected_header('Host', sel_host or host)
for name, value in self.parent.addheaders:
- name = name.capitalize()
+ name = name.title()
if not request.has_header(name):
request.add_unredirected_header(name, value)
@@ -1145,7 +1145,7 @@ class FileHandler(BaseHandler):
modified = email.Utils.formatdate(stats.st_mtime, usegmt=True)
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)
@@ -1198,9 +1198,9 @@ class FTPHandler(BaseHandler):
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())