Ticket #7535: static.py.3.patch

File static.py.3.patch, 907 bytes (added by Kevin Hunter <hunteke@…>, 16 years ago)

Content-Encoding patch for django.views.static.serve, revision 3, hopefully final

  • static.py

     
    5959    if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
    6060                              statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]):
    6161        return HttpResponseNotModified()
    62     mimetype = mimetypes.guess_type(fullpath)[0] or 'application/octet-stream'
     62
     63    mimetype, encoding = mimetypes.guess_type(fullpath)
     64    mimetype = mimetype or 'application/octet-stream'
     65
    6366    contents = open(fullpath, 'rb').read()
    6467    response = HttpResponse(contents, mimetype=mimetype)
     68
    6569    response["Last-Modified"] = http_date(statobj[stat.ST_MTIME])
     70    if encoding:
     71        response["Content-Encoding"] = encoding
    6672    response["Content-Length"] = len(contents)
     73
    6774    return response
    6875
    6976DEFAULT_DIRECTORY_INDEX_TEMPLATE = """
Back to Top