1. Luke Plant
  2. django

Commits

cca...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed 2334589

[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.

  • Participants
  • Parent commits bf80620
  • Branches soc2009/http-wsgi-improvements

Comments (0)

Files changed (2)

File django/core/handlers/wsgi.py

View file
  • Ignore whitespace
                 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
 

File django/http/__init__.py

View file
  • Ignore whitespace
 
     _status_code = 200
     _codec = None
+    _charset = None
 
     def __init__(self, content='', mimetype=None, status=None,
                  content_type=None, request=None):
         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):
         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')