From 43e7555b09e829179a9c9dbcf1b0e8def22a2e8b Mon Sep 17 00:00:00 2001 From: Hazmo Date: Sun, 22 Apr 2018 11:00:35 +0000 Subject: [PATCH 1/5] Update common.py to add USE_APACHE_HEADERS set to false --- api/config/settings/common.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/config/settings/common.py b/api/config/settings/common.py index 5e895bea5..cab3b7607 100644 --- a/api/config/settings/common.py +++ b/api/config/settings/common.py @@ -390,6 +390,11 @@ REST_FRAMEWORK = { ATOMIC_REQUESTS = False USE_X_FORWARDED_HOST = True USE_X_FORWARDED_PORT = True + +# Wether we should use Apache or Nginx headers when serving audio files +# Default to Nginx +USE_APACHE_HEADERS = False + # 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 From 5879d2d65520a013e55311c98411e47221cca1fd Mon Sep 17 00:00:00 2001 From: Hazmo Date: Sun, 22 Apr 2018 11:08:57 +0000 Subject: [PATCH 2/5] Update views.py to modify headers depending on Nginx or Apache --- api/funkwhale_api/music/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/funkwhale_api/music/views.py b/api/funkwhale_api/music/views.py index d03b55e50..019525018 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.USE_APACHE_HEADERS: + response['X-Sendfile'] = file_path + else: + response['X-Accel-Redirect'] = file_path filename = "filename*=UTF-8''{}".format( urllib.parse.quote(filename)) response["Content-Disposition"] = "attachment; {}".format(filename) From 0695cd85e14dada3c118411c3ba3740da7fe801d Mon Sep 17 00:00:00 2001 From: Hazmo Date: Sun, 22 Apr 2018 11:54:35 +0000 Subject: [PATCH 3/5] Update common.py with future proof REVERSE_PROXY_TYPE setting --- api/config/settings/common.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/config/settings/common.py b/api/config/settings/common.py index cab3b7607..de1d653cb 100644 --- a/api/config/settings/common.py +++ b/api/config/settings/common.py @@ -391,9 +391,10 @@ ATOMIC_REQUESTS = False USE_X_FORWARDED_HOST = True USE_X_FORWARDED_PORT = True -# Wether we should use Apache or Nginx headers when serving audio files +# Wether we should use Apache, Nginx (or other) headers when serving audio files # Default to Nginx -USE_APACHE_HEADERS = False +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) From be7e8e1e7e8078d93d86f5c45d1ad866f0515618 Mon Sep 17 00:00:00 2001 From: Hazmo Date: Sun, 22 Apr 2018 11:59:41 +0000 Subject: [PATCH 4/5] Update views.py to adapt headers based on REVERSE_PROXY_TYPE --- api/funkwhale_api/music/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/funkwhale_api/music/views.py b/api/funkwhale_api/music/views.py index 019525018..e2ff6a79e 100644 --- a/api/funkwhale_api/music/views.py +++ b/api/funkwhale_api/music/views.py @@ -238,9 +238,9 @@ class TrackFileViewSet(viewsets.ReadOnlyModelViewSet): f.serve_from_source_path) response = Response() filename = f.filename - if settings.USE_APACHE_HEADERS: + if settings.REVERSE_PROXY_TYPE == 'apache': response['X-Sendfile'] = file_path - else: + elif settings.REVERSE_PROXY_TYPE == 'nginx': response['X-Accel-Redirect'] = file_path filename = "filename*=UTF-8''{}".format( urllib.parse.quote(filename)) From 66597a1874c7d5831b3931c04d1d9fbef1ca82d0 Mon Sep 17 00:00:00 2001 From: Hazmo Date: Sun, 22 Apr 2018 12:14:19 +0000 Subject: [PATCH 5/5] Update views.py, typo on apache --- api/funkwhale_api/music/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/funkwhale_api/music/views.py b/api/funkwhale_api/music/views.py index e2ff6a79e..224d085b6 100644 --- a/api/funkwhale_api/music/views.py +++ b/api/funkwhale_api/music/views.py @@ -238,7 +238,7 @@ class TrackFileViewSet(viewsets.ReadOnlyModelViewSet): f.serve_from_source_path) response = Response() filename = f.filename - if settings.REVERSE_PROXY_TYPE == 'apache': + if settings.REVERSE_PROXY_TYPE == 'apache2': response['X-Sendfile'] = file_path elif settings.REVERSE_PROXY_TYPE == 'nginx': response['X-Accel-Redirect'] = file_path