Added more dict-like methods to HttpResponse as part of the response.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
This commit is contained in:
parent
71796410ba
commit
ca9388cdaf
|
@ -159,8 +159,8 @@ class ModPythonHandler(BaseHandler):
|
||||||
|
|
||||||
# Convert our custom HttpResponse object back into the mod_python req.
|
# Convert our custom HttpResponse object back into the mod_python req.
|
||||||
req.content_type = response['Content-Type']
|
req.content_type = response['Content-Type']
|
||||||
for key, value in response.headers.items():
|
for key, value in response.items():
|
||||||
if key != 'Content-Type':
|
if key != 'content-type':
|
||||||
req.headers_out[str(key)] = str(value)
|
req.headers_out[str(key)] = str(value)
|
||||||
for c in response.cookies.values():
|
for c in response.cookies.values():
|
||||||
req.headers_out.add('Set-Cookie', c.output(header=''))
|
req.headers_out.add('Set-Cookie', c.output(header=''))
|
||||||
|
|
|
@ -208,7 +208,7 @@ class WSGIHandler(BaseHandler):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
status_text = 'UNKNOWN STATUS CODE'
|
status_text = 'UNKNOWN STATUS CODE'
|
||||||
status = '%s %s' % (response.status_code, status_text)
|
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():
|
for c in response.cookies.values():
|
||||||
response_headers.append(('Set-Cookie', str(c.output(header=''))))
|
response_headers.append(('Set-Cookie', str(c.output(header=''))))
|
||||||
start_response(status, response_headers)
|
start_response(status, response_headers)
|
||||||
|
|
|
@ -275,6 +275,12 @@ class HttpResponse(object):
|
||||||
|
|
||||||
__contains__ = has_header
|
__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):
|
def set_cookie(self, key, value='', max_age=None, expires=None, path='/', domain=None, secure=None):
|
||||||
self.cookies[key] = value
|
self.cookies[key] = value
|
||||||
for var in ('max_age', 'path', 'domain', 'secure', 'expires'):
|
for var in ('max_age', 'path', 'domain', 'secure', 'expires'):
|
||||||
|
|
|
@ -20,7 +20,7 @@ class GZipMiddleware(object):
|
||||||
|
|
||||||
# Avoid gzipping if we've already got a content-encoding or if the
|
# Avoid gzipping if we've already got a content-encoding or if the
|
||||||
# content-type is Javascript (silly IE...)
|
# 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:
|
if response.has_header('Content-Encoding') or is_js:
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue