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
merge-requests/154/head
banana 2018-04-22 15:11:04 +02:00
rodzic 8f24d69998
commit 0f7de68f0d
2 zmienionych plików z 10 dodań i 1 usunięć

Wyświetl plik

@ -390,6 +390,12 @@ REST_FRAMEWORK = {
ATOMIC_REQUESTS = False ATOMIC_REQUESTS = False
USE_X_FORWARDED_HOST = True USE_X_FORWARDED_HOST = True
USE_X_FORWARDED_PORT = 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 # Wether we should check user permission before serving audio files (meaning
# return an obfuscated url) # return an obfuscated url)
# This require a special configuration on the reverse proxy side # This require a special configuration on the reverse proxy side

Wyświetl plik

@ -238,7 +238,10 @@ class TrackFileViewSet(viewsets.ReadOnlyModelViewSet):
f.serve_from_source_path) f.serve_from_source_path)
response = Response() response = Response()
filename = f.filename 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( filename = "filename*=UTF-8''{}".format(
urllib.parse.quote(filename)) urllib.parse.quote(filename))
response["Content-Disposition"] = "attachment; {}".format(filename) response["Content-Disposition"] = "attachment; {}".format(filename)