fix(api): ensure non ascii paths are handled by X-Accel-Redirect (#2861)
This commit is contained in:
parent
6f84328380
commit
0ce63f3bf0
|
@ -2,6 +2,7 @@ import os
|
|||
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.encoding import iri_to_uri
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.serializers import IntegerField
|
||||
|
@ -23,5 +24,9 @@ class FileViewSet(viewsets.ModelViewSet):
|
|||
|
||||
response = HttpResponse()
|
||||
response["Content-Type"] = file.mime
|
||||
response["X-Accel-Redirect"] = os.path.join("/api/_media", file.filepath)
|
||||
|
||||
# HTTP headers must be USASCII encoded, or Nginx might not find the file and
|
||||
# will return a 404.
|
||||
redirect_uri = iri_to_uri(os.path.join("/api/_media", file.filepath))
|
||||
response["X-Accel-Redirect"] = redirect_uri
|
||||
return response
|
||||
|
|
Loading…
Reference in New Issue