Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ntrrgc/lasana
Browse files Browse the repository at this point in the history
  • Loading branch information
ntrrgc committed Sep 5, 2013
2 parents ab911ea + bf61844 commit f789725
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sendfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
import mimetypes

from . settings import LASANA_USE_X_SENDFILE
from . settings import LASANA_USE_X_SENDFILE, LASANA_NGINX_ACCEL_REDIRECT_BASE_URL

#For no-XSendfile approach
from django.core.servers.basehttp import FileWrapper
Expand Down Expand Up @@ -39,8 +39,15 @@ def send(request, file):
else:
# Throw 416 Range Not Satisfiable
return HttpResponse(status=416)
response['X-Sendfile2'] = "%s %s-%s" % (urlquote(file.path), str(range_begin) if range_begin is not None else "0",
str(range_end) if range_end is not None else "")

if LASANA_USE_X_SENDFILE == 'lighttpd':
response['X-Sendfile2'] = "%s %s-%s" % (urlquote(file.path), str(range_begin) if range_begin is not None else "0",
str(range_end) if range_end is not None else "")
elif LASANA_USE_X_SENDFILE == 'nginx':
response['X-Accel-Redirect'] = (LASANA_NGINX_ACCEL_REDIRECT_BASE_URL + os.path.basename(file.name)).encode('UTF-8')
else:
raise RuntimeError('LASANA_USE_X_SENDFILE must be "lighttpd" or "nginx".')

return response
else:
response = HttpResponse(FileWrapper(file), content_type=detected_type)
Expand Down
2 changes: 2 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ def get(key, default):
LASANA_USE_X_SENDFILE = get('LASANA_USE_X_SENDFILE', False)

LASANA_UPLOAD_ROOT = get('LASANA_UPLOAD_ROOT', './uploads')

LASANA_NGINX_ACCEL_REDIRECT_BASE_URL = get('LASANA_NGINX_ACCEL_REDIRECT_BASE_URL', '/__uploads/')

0 comments on commit f789725

Please sign in to comment.