Commits

David Bennett committed 4f4f963

Added X-SendFile handler.

  • Participants
  • Parent commits b23045a

Comments (0)

Files changed (1)

File private_media/handlers.py

+import mimetypes
 from urlparse import urljoin
 from django.conf import settings
 from django.http import HttpResponse
 
 def nginx(request, file):
     response = HttpResponse()
+    # Let nginx figure out the Content-Type
     response['Content-Type'] = ''
     response['X-Accel-Redirect'] = urljoin(
         settings.PRIVATE_MEDIA_URL, file.name)
     return response
+
+
+def xsendfile(request, file):
+    response = HttpResponse()
+    mimetype, encoding = mimetypes.guess_type(file.name)
+    response['Content-Type'] = mimetype or 'application/octet-stream'
+    response["X-SendFile"] = file.path
+    return response