From 32c87d8197923e6388b2d0bcedc85b908edbeb69 Mon Sep 17 00:00:00 2001 From: stux! Date: Sat, 15 Oct 2016 00:17:45 +0200 Subject: [PATCH 1/2] Modified django-sendfile. --- sendfile/backends/_internalredirect.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sendfile/backends/_internalredirect.py b/sendfile/backends/_internalredirect.py index be4e069..3538d70 100644 --- a/sendfile/backends/_internalredirect.py +++ b/sendfile/backends/_internalredirect.py @@ -9,7 +9,7 @@ from urllib import quote -def _convert_file_to_url(filename): +def _convert_file_to_url(filename, quote_url=True): relpath = os.path.relpath(filename, settings.SENDFILE_ROOT) url = [settings.SENDFILE_URL] @@ -21,4 +21,7 @@ def _convert_file_to_url(filename): # Python3 urllib.parse.quote accepts both unicode and bytes, while Python2 urllib.quote only accepts bytes. # So use bytes for quoting and then go back to unicode. url = [smart_bytes(url_component) for url_component in url] - return smart_text(quote(b'/'.join(url))) + url = b'/'.join(url) + if quote_url: + url = quote(url) + return smart_text(url) From 848a7f73aa3121baf228f9f618fc5e11f06e7f5e Mon Sep 17 00:00:00 2001 From: stux! Date: Sat, 15 Oct 2016 00:23:58 +0200 Subject: [PATCH 2/2] Forgot to tell nginx.py not to quote urls. --- sendfile/backends/nginx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendfile/backends/nginx.py b/sendfile/backends/nginx.py index 29dc348..2a892f2 100644 --- a/sendfile/backends/nginx.py +++ b/sendfile/backends/nginx.py @@ -7,7 +7,7 @@ def sendfile(request, filename, **kwargs): response = HttpResponse() - url = _convert_file_to_url(filename) + url = _convert_file_to_url(filename, quote_url=False) response['X-Accel-Redirect'] = url.encode('utf-8') return response