Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed the way we handle HTTP headers internally so that they appear

case-insensitive, but the original case is preserved for output. This increases the chances of working with non-compliant clients without changing the external interface. Fixed #2970.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6546 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 706659d2bb6af350903a5b5ee9d1e09f95f6a9a3 1 parent e172e7b
@malcolmt malcolmt authored
Showing with 10 additions and 6 deletions.
  1. +10 −6 django/http/__init__.py
View
16 django/http/__init__.py
@@ -261,19 +261,23 @@ def __init__(self, content='', mimetype=None, status=None,
else:
self._container = [content]
self._is_string = True
- self._headers = {'content-type': content_type}
self.cookies = SimpleCookie()
if status:
self.status_code = status
+ # _headers is a mapping of the lower-case name to the original case of
+ # the header (required for working with legacy systems) and the header
+ # value.
+ self._headers = {'content-type': ('Content-Type', content_type)}
+
def __str__(self):
"Full HTTP message, including headers"
return '\n'.join(['%s: %s' % (key, value)
- for key, value in self._headers.items()]) \
+ for key, value in self._headers.values()]) \
+ '\n\n' + self.content
def __setitem__(self, header, value):
- self._headers[header.lower()] = value
+ self._headers[header.lower()] = (header, value)
def __delitem__(self, header):
try:
@@ -282,7 +286,7 @@ def __delitem__(self, header):
pass
def __getitem__(self, header):
- return self._headers[header.lower()]
+ return self._headers[header.lower()][1]
def has_header(self, header):
"Case-insensitive check for a header"
@@ -291,10 +295,10 @@ def has_header(self, header):
__contains__ = has_header
def items(self):
- return self._headers.items()
+ return self._headers.values()
def get(self, header, alternate):
- return self._headers.get(header.lower(), alternate)
+ return self._headers.get(header.lower(), (None, alternate))[1]
def set_cookie(self, key, value='', max_age=None, expires=None, path='/', domain=None, secure=None):
self.cookies[key] = value
Please sign in to comment.
Something went wrong with that request. Please try again.