Skip to content

Commit

Permalink
Added more dict-like methods to HttpResponse as part of the response.…
Browse files Browse the repository at this point in the history
…headers -> response._headers move, and fixed a few direct uses of response.headers in Django itself. Thanks to PhiR for tracking down and slaying these bugs.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6235 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jacobian committed Sep 14, 2007
1 parent 7179641 commit ca9388c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions django/core/handlers/modpython.py
Expand Up @@ -159,8 +159,8 @@ def __call__(self, req):

# Convert our custom HttpResponse object back into the mod_python req.
req.content_type = response['Content-Type']
for key, value in response.headers.items():
if key != 'Content-Type':
for key, value in response.items():
if key != 'content-type':
req.headers_out[str(key)] = str(value)
for c in response.cookies.values():
req.headers_out.add('Set-Cookie', c.output(header=''))
Expand Down
2 changes: 1 addition & 1 deletion django/core/handlers/wsgi.py
Expand Up @@ -208,7 +208,7 @@ def __call__(self, environ, start_response):
except KeyError:
status_text = 'UNKNOWN STATUS CODE'
status = '%s %s' % (response.status_code, status_text)
response_headers = [(str(k), str(v)) for k, v in response.headers.items()]
response_headers = [(str(k), str(v)) for k, v in response.items()]
for c in response.cookies.values():
response_headers.append(('Set-Cookie', str(c.output(header=''))))
start_response(status, response_headers)
Expand Down
6 changes: 6 additions & 0 deletions django/http/__init__.py
Expand Up @@ -274,6 +274,12 @@ def has_header(self, header):
return self._headers.has_key(header.lower())

__contains__ = has_header

def items(self):
return self._headers.items()

def get(self, header, alternate):
return self._headers.get(header, alternate)

def set_cookie(self, key, value='', max_age=None, expires=None, path='/', domain=None, secure=None):
self.cookies[key] = value
Expand Down
2 changes: 1 addition & 1 deletion django/middleware/gzip.py
Expand Up @@ -20,7 +20,7 @@ def process_response(self, request, response):

# Avoid gzipping if we've already got a content-encoding or if the
# content-type is Javascript (silly IE...)
is_js = "javascript" in response.headers.get('Content-Type', '').lower()
is_js = "javascript" in response.get('Content-Type', '').lower()
if response.has_header('Content-Encoding') or is_js:
return response

Expand Down

0 comments on commit ca9388c

Please sign in to comment.