﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15281	Staticfiles sever view should use generator	FunkyBob	Jannis Leidel	"Especially for larger files, this can greatly improve the response times.

Also, there's no reason for this module to use dict-style access to the stat object.

{{{
Index: django/contrib/staticfiles/views.py
===================================================================
--- django/contrib/staticfiles/views.py	(revision 15490)
+++ django/contrib/staticfiles/views.py	(working copy)
@@ -7,7 +7,6 @@
 import os
 import posixpath
 import re
-import stat
 import urllib
 from email.Utils import parsedate_tz, mktime_tz
 
@@ -80,12 +79,12 @@
     mimetype, encoding = mimetypes.guess_type(fullpath)
     mimetype = mimetype or 'application/octet-stream'
     if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
-                              statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]):
+                              statobj.st_mtime, statobj.st_size):
         return HttpResponseNotModified(mimetype=mimetype)
-    contents = open(fullpath, 'rb').read()
-    response = HttpResponse(contents, mimetype=mimetype)
-    response[""Last-Modified""] = http_date(statobj[stat.ST_MTIME])
-    response[""Content-Length""] = len(contents)
+    contents = open(fullpath, 'rb')
+    response = HttpResponse(iter(contents), mimetype=mimetype)
+    response[""Last-Modified""] = http_date(statobj.st_mtime)
+    response[""Content-Length""] = statobj.st_size
     if encoding:
         response[""Content-Encoding""] = encoding
     return response
}}}

This does, however, make the view susceptible to generator-consuming middleware, but that's another swag of tickets."	New feature	closed	contrib.staticfiles	dev	Normal	fixed	generator	Aymeric Augustin	Accepted	1	0	0	1	0	0
