Ticket #7535: static.py.2.patch

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

Content-Encoding patch for django.views.static.serve, revision 2

  • 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 = mimetypes.guess_type(fullpath)
     64    encoding = mimetype[1] or None
     65    mimetype = mimetype[0] or 'application/octet-stream'
     66
    6367    contents = open(fullpath, 'rb').read()
    6468    response = HttpResponse(contents, mimetype=mimetype)
     69
    6570    response["Last-Modified"] = http_date(statobj[stat.ST_MTIME])
     71    if encoding:
     72        response["Content-Encoding"] = encoding
    6673    response["Content-Length"] = len(contents)
     74
    6775    return response
    6876
    6977DEFAULT_DIRECTORY_INDEX_TEMPLATE = """
Back to Top