diff --git a/oxdjango/http.py b/oxdjango/http.py index aadea00..ddf149d 100644 --- a/oxdjango/http.py +++ b/oxdjango/http.py @@ -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