From 0f7de68f0da7d036f8ea291c6240ac20c231f196 Mon Sep 17 00:00:00 2001 From: banana Date: Sun, 22 Apr 2018 15:11:04 +0200 Subject: [PATCH] Update common.py to add USE_APACHE_HEADERS set to false Update views.py to modify headers depending on Nginx or Apache Update common.py with future proof REVERSE_PROXY_TYPE setting Update views.py to adapt headers based on REVERSE_PROXY_TYPE Update views.py, typo on apache --- api/config/settings/common.py | 6 ++++++ api/funkwhale_api/music/views.py | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/api/config/settings/common.py b/api/config/settings/common.py index 5e895bea5..de1d653cb 100644 --- a/api/config/settings/common.py +++ b/api/config/settings/common.py @@ -390,6 +390,12 @@ REST_FRAMEWORK = { ATOMIC_REQUESTS = False USE_X_FORWARDED_HOST = True USE_X_FORWARDED_PORT = True + +# Wether we should use Apache, Nginx (or other) headers when serving audio files +# Default to Nginx +REVERSE_PROXY_TYPE = env('REVERSE_PROXY_TYPE', default='nginx') +assert REVERSE_PROXY_TYPE in ['apache2', 'nginx'], 'Unsupported REVERSE_PROXY_TYPE' + # Wether we should check user permission before serving audio files (meaning # return an obfuscated url) # This require a special configuration on the reverse proxy side diff --git a/api/funkwhale_api/music/views.py b/api/funkwhale_api/music/views.py index d03b55e50..224d085b6 100644 --- a/api/funkwhale_api/music/views.py +++ b/api/funkwhale_api/music/views.py @@ -238,7 +238,10 @@ class TrackFileViewSet(viewsets.ReadOnlyModelViewSet): f.serve_from_source_path) response = Response() filename = f.filename - response['X-Accel-Redirect'] = file_path + if settings.REVERSE_PROXY_TYPE == 'apache2': + response['X-Sendfile'] = file_path + elif settings.REVERSE_PROXY_TYPE == 'nginx': + response['X-Accel-Redirect'] = file_path filename = "filename*=UTF-8''{}".format( urllib.parse.quote(filename)) response["Content-Disposition"] = "attachment; {}".format(filename)