Skip to content
Snippets Groups Projects
Commit 5f6b1ae6 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Merge branch 'develop' into 'develop'

Adapt Headers for serving audio files

See merge request funkwhale/funkwhale!154
parents 8f24d699 74dcf51c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment