Ticket #9106: django-static-serve-chunks.diff

File django-static-serve-chunks.diff, 1.1 KB (added by Michael Manfre <mmanfre@…>, 7 years ago)
  • django/views/static.py

     
    1515from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseNotModified
    1616from django.template import Template, Context, TemplateDoesNotExist
    1717from django.utils.http import http_date
     18from django.core.files import File
    1819
    1920def serve(request, path, document_root=None, show_indexes=False):
    2021    """
     
    6061                              statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]):
    6162        return HttpResponseNotModified()
    6263    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()
    6466    response = HttpResponse(contents, mimetype=mimetype)
    6567    response["Last-Modified"] = http_date(statobj[stat.ST_MTIME])
    66     response["Content-Length"] = len(contents)
     68    response["Content-Length"] = f.size
    6769    return response
    6870
    6971DEFAULT_DIRECTORY_INDEX_TEMPLATE = """
Back to Top