better x-accel-redirect support
This commit is contained in:
parent
309f889670
commit
7acf61684e
1 changed files with 9 additions and 3 deletions
|
@ -12,11 +12,17 @@ def HttpFileResponse(path, content_type=None, filename=None):
|
|||
raise Http404
|
||||
if not content_type:
|
||||
content_type = mimetypes.guess_type(path)[0]
|
||||
if hasattr(settings, 'XACCELREDIRECT') and settings.XACCELREDIRECT:
|
||||
if settings.XACCELREDIRECT:
|
||||
response = HttpResponse()
|
||||
response['X-Accel-Redirect'] = path.replace(*settings.XACCELREDIRECT)
|
||||
response['Content-Type'] = content_type
|
||||
response['Content-Length'] = os.stat(path).st_size
|
||||
if not isinstance(settings.XACCELREDIRECT, bool):
|
||||
path = path.replace(*settings.XACCELREDIRECT)
|
||||
if path.startswith(settings.STATIC_ROOT):
|
||||
path = settings.STATIC_URL + path[len(settings.STATIC_ROOT)+1:]
|
||||
if path.startswith(settings.MEDIA_ROOT):
|
||||
path = settings.MEDIA_URL + path[len(settings.MEDIA_ROOT)+1:]
|
||||
response['X-Accel-Redirect'] = path
|
||||
response['Content-Type'] = content_type
|
||||
elif settings.XSENDFILE:
|
||||
response = HttpResponse()
|
||||
response['X-Sendfile'] = path
|
||||
|
|
Loading…
Reference in a new issue