Ticket #9106: django-static-serve-chunks.diff
File django-static-serve-chunks.diff, 1.1 KB (added by , 16 years ago) |
---|
-
django/views/static.py
15 15 from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseNotModified 16 16 from django.template import Template, Context, TemplateDoesNotExist 17 17 from django.utils.http import http_date 18 from django.core.files import File 18 19 19 20 def serve(request, path, document_root=None, show_indexes=False): 20 21 """ … … 60 61 statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]): 61 62 return HttpResponseNotModified() 62 63 mimetype = mimetypes.guess_type(fullpath)[0] or 'application/octet-stream' 63 contents = open(fullpath, 'rb').read() 64 f = File(open(fullpath, 'rb')) 65 contents = f.chunks() 64 66 response = HttpResponse(contents, mimetype=mimetype) 65 67 response["Last-Modified"] = http_date(statobj[stat.ST_MTIME]) 66 response["Content-Length"] = len(contents)68 response["Content-Length"] = f.size 67 69 return response 68 70 69 71 DEFAULT_DIRECTORY_INDEX_TEMPLATE = """