Index: urllib2.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/urllib2.py,v retrieving revision 1.72 diff -u -r1.72 urllib2.py --- urllib2.py 11 Jul 2004 17:14:12 -0000 1.72 +++ urllib2.py 22 Jul 2004 20:44:08 -0000 @@ -256,11 +256,11 @@ def add_header(self, key, val): # useful for something like authentication - self.headers[key.capitalize()] = val + self.headers[key] = 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] = val def has_header(self, header_name): return (header_name in self.headers or @@ -279,7 +279,7 @@ 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 = {} @@ -520,10 +520,10 @@ def http_error_302(self, req, fp, code, msg, headers): # Some servers (incorrectly) return multiple Location headers # (so probably same goes for URI). Use first header. - if 'location' in headers: - newurl = headers.getheaders('location')[0] - elif 'uri' in headers: - newurl = headers.getheaders('uri')[0] + if 'Location' in headers: + newurl = headers.getheaders('Location')[0] + elif 'URI' in headers: + newurl = headers.getheaders('URI')[0] else: return newurl = urlparse.urljoin(req.get_full_url(), newurl) @@ -584,7 +584,7 @@ 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: @@ -738,17 +738,17 @@ def http_error_401(self, req, fp, code, msg, headers): host = urlparse.urlparse(req.get_full_url())[1] - return self.http_error_auth_reqed('www-authenticate', + return self.http_error_auth_reqed('WWW-Authenticate', host, req, 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() - return self.http_error_auth_reqed('proxy-authenticate', + return self.http_error_auth_reqed('Proxy-Authenticate', host, req, headers) @@ -913,7 +913,7 @@ def http_error_401(self, req, fp, code, msg, headers): host = urlparse.urlparse(req.get_full_url())[1] - retry = self.http_error_auth_reqed('www-authenticate', + retry = self.http_error_auth_reqed('WWW-Authenticate', host, req, headers) self.reset_retry_count() return retry @@ -925,7 +925,7 @@ def http_error_407(self, req, fp, code, msg, headers): host = req.get_host() - retry = self.http_error_auth_reqed('proxy-authenticate', + retry = self.http_error_auth_reqed('Proxy-Authenticate', host, req, headers) self.reset_retry_count() return retry @@ -945,13 +945,13 @@ 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) @@ -1125,7 +1125,7 @@ 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) @@ -1178,9 +1178,9 @@ 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()) Index: test/test_urllib2.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_urllib2.py,v retrieving revision 1.18 diff -u -r1.18 test_urllib2.py --- test/test_urllib2.py 11 Jul 2004 17:14:13 -0000 1.18 +++ test/test_urllib2.py 22 Jul 2004 20:44:10 -0000 @@ -330,8 +330,8 @@ self.assertEqual(h.ftpwrapper.filename, filename) self.assertEqual(h.ftpwrapper.filetype, type_) headers = r.info() - self.assertEqual(headers.get("Content-type"), mimetype) - self.assertEqual(int(headers["Content-length"]), len(data)) + self.assertEqual(headers.get("Content-Type"), mimetype) + self.assertEqual(int(headers["Content-Length"]), len(data)) def test_file(self): import time, rfc822, socket @@ -367,9 +367,9 @@ finally: os.remove(TESTFN) self.assertEqual(data, towrite) - self.assertEqual(headers["Content-type"], "text/plain") - self.assertEqual(headers["Content-length"], "13") - self.assertEqual(headers["Last-modified"], modified) + self.assertEqual(headers["Content-Type"], "text/plain") + self.assertEqual(headers["Content-Length"], "13") + self.assertEqual(headers["Last-Modified"], modified) for url in [ "file://localhost:80%s" % urlpath, @@ -483,24 +483,24 @@ r = MockResponse(200, "OK", {}, "") newreq = h.do_request_(req) if data is None: # GET - self.assert_("Content-length" not in req.unredirected_hdrs) - self.assert_("Content-type" not in req.unredirected_hdrs) + self.assert_("Content-Length" not in req.unredirected_hdrs) + self.assert_("Content-Type" not in req.unredirected_hdrs) else: # POST - self.assertEqual(req.unredirected_hdrs["Content-length"], "0") - self.assertEqual(req.unredirected_hdrs["Content-type"], + self.assertEqual(req.unredirected_hdrs["Content-Length"], "0") + self.assertEqual(req.unredirected_hdrs["Content-Type"], "application/x-www-form-urlencoded") # XXX the details of Host could be better tested self.assertEqual(req.unredirected_hdrs["Host"], "example.com") self.assertEqual(req.unredirected_hdrs["Spam"], "eggs") # don't clobber existing headers - req.add_unredirected_header("Content-length", "foo") - req.add_unredirected_header("Content-type", "bar") + req.add_unredirected_header("Content-Length", "foo") + req.add_unredirected_header("Content-Type", "bar") req.add_unredirected_header("Host", "baz") req.add_unredirected_header("Spam", "foo") newreq = h.do_request_(req) - self.assertEqual(req.unredirected_hdrs["Content-length"], "foo") - self.assertEqual(req.unredirected_hdrs["Content-type"], "bar") + self.assertEqual(req.unredirected_hdrs["Content-Length"], "foo") + self.assertEqual(req.unredirected_hdrs["Content-Type"], "bar") self.assertEqual(req.unredirected_hdrs["Host"], "baz") self.assertEqual(req.unredirected_hdrs["Spam"], "foo") @@ -551,7 +551,7 @@ req.add_unredirected_header("Spam", "spam") try: method(req, MockFile(), code, "Blah", - MockHeaders({"location": to_url})) + MockHeaders({"Location": to_url})) except urllib2.HTTPError: # 307 in response to POST requires user OK self.assert_(code == 307 and data is not None) @@ -569,6 +569,6 @@ req = Request(from_url) def redirect(h, req, url=to_url): h.http_error_302(req, MockFile(), 302, "Blah", - MockHeaders({"location": url})) + MockHeaders({"Location": url})) # Note that the *original* request shares the same record of # redirections with the sub-requests caused by the redirections.