summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Cahoon <chris.cahoon@gmail.com>2009-07-24 19:31:12 +0000
committerChris Cahoon <chris.cahoon@gmail.com>2009-07-24 19:31:12 +0000
commit76fdeaf7209c6ef9d0263a205a53891b1f2da8a0 (patch)
treea5506c55ce11022bc68b5ec3679914ab944032f0
parentbe96986ce80db723d5211a1f00a61785010aa815 (diff)
downloaddjango-76fdeaf7209c6ef9d0263a205a53891b1f2da8a0.tar.gz
[soc2009/http-wsgi-improvements] Remove setting the Content-Length header for HttpResponseSendFile from the handler, for compatibility, and add a content attribute. Refs #2131.
Also adds a _charset class attribute to HttpResponse so the children all have it. git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/http-wsgi-improvements@11326 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/handlers/wsgi.py7
-rw-r--r--django/http/__init__.py8
2 files changed, 9 insertions, 6 deletions
diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py
index e96ef44550..359d4b5425 100644
--- a/django/core/handlers/wsgi.py
+++ b/django/core/handlers/wsgi.py
@@ -251,12 +251,7 @@ class WSGIHandler(base.BaseHandler):
filelike = open(filename, 'rb')
return environ['wsgi.file_wrapper'](filelike,
response.block_size)
- else:
- import os.path
- if not os.path.exists(filename):
- raise Exception("Filename provided to HttpResponseSendFile does not exist.")
- response_headers.append(('Content-Length',
- str(os.path.getsize(filename))))
+
start_response(status, response_headers)
return response
diff --git a/django/http/__init__.py b/django/http/__init__.py
index 1d4875b2db..55592d628f 100644
--- a/django/http/__init__.py
+++ b/django/http/__init__.py
@@ -272,6 +272,7 @@ class HttpResponse(object):
_status_code = 200
_codec = None
+ _charset = None
def __init__(self, content='', mimetype=None, status=None,
content_type=None, request=None):
@@ -446,6 +447,8 @@ class HttpResponseSendFile(HttpResponse):
self.block_size = block_size
self['Content-Disposition'] = ('attachment; filename=%s' %
os.path.basename(path_to_file))
+ if not settings.HTTPRESPONSE_SENDFILE_HEADER and os.path.exists(path_to_file):
+ self['Content-Length'] = str(os.path.getsize(path_to_file))
self._empty_content = False
def set_empty_content(self):
@@ -457,6 +460,11 @@ class HttpResponseSendFile(HttpResponse):
from django.core.servers.basehttp import FileWrapper
return FileWrapper(self.get_file_handler(), self.block_size)
+ def _get_content(self):
+ return "".join(self.iter())
+
+ content = property(_get_content)
+
def get_file_handler(self):
if not self.sendfile_fh:
self.sendfile_fh = open(self.sendfile_filename, 'rb')