Django FileResponse через nginx ошибка ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION

django использует FileResponse и запускает сервер на 8000 порту.

# this add Content-Disposition header in response
response = FileResponse(file, filename="file.txt", as_attachment=True) 

nginx proxy_pass to django:

location /api/v1/download {
       proxy_pass http://127.0.0.1:8000;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_set_header Host $http_host;
       proxy_set_header X-Real_IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

когда я обращаюсь к django напрямую, я успешно скачиваю файл, но когда я обращаюсь к django через nginx, chrome выдает ошибку ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION.

Используйте curl для отправки запроса к django напрямую:

curl -v http://django:8000

< HTTP/1.1 200 OK
< Server: WSGIServer/0.2 CPython/3.9.2
< Content-Type: application/octet-stream
< Content-Disposition: attachment; filename="filename.txt"   # django add
< Vary: Accept, Cookie
< Allow: GET, HEAD, OPTIONS
< X-Content-Type-Options: nosniff
< Referrer-Policy: same-origin
< Connection: close

Используя curl для отправки запроса на nginx, он показывает дублированный заголовок ответа Content-Disposition:

curl -v https://nginx

< HTTP/1.1 200 OK
< Server: nginx/1.20.1
< Date: Mon, 04 Oct 2021 16:39:01 GMT
< Content-Type: application/octet-stream
< Transfer-Encoding: chunked
< Connection: keep-alive
< Content-Disposition: attachment; filename="filename.txt"   # django add
< Vary: Accept, Cookie
< Allow: GET, HEAD, OPTIONS
< X-Content-Type-Options: nosniff
< Referrer-Policy: same-origin
< Content-Disposition: “attachment”    # nginx add

Почему nginx auto Content-Disposition: "attachment" In response header? Есть ли способ избежать этого?

Вернуться на верх