From 254ad2e3450d8175170914f06af8358d2becc35b Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 14 Mar 2023 05:45:30 +0100 Subject: [PATCH] Fixed #34405 -- Fixed setting Content-Type header in FileResponse for compress and brotli. Thanks Chamal De Silva for the report. --- django/http/response.py | 2 ++ tests/responses/test_fileresponse.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/django/http/response.py b/django/http/response.py index f62dec8ce99..3b611e78f58 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -609,7 +609,9 @@ class FileResponse(StreamingHttpResponse): # Encoding isn't set to prevent browsers from automatically # uncompressing files. content_type = { + "br": "application/x-brotli", "bzip2": "application/x-bzip", + "compress": "application/x-compress", "gzip": "application/gzip", "xz": "application/x-xz", }.get(encoding, content_type) diff --git a/tests/responses/test_fileresponse.py b/tests/responses/test_fileresponse.py index 952fe4dd7c5..d14eb82c626 100644 --- a/tests/responses/test_fileresponse.py +++ b/tests/responses/test_fileresponse.py @@ -253,8 +253,10 @@ class FileResponseTests(SimpleTestCase): """ test_tuples = ( (".tar.gz", "application/gzip"), + (".tar.br", "application/x-brotli"), (".tar.bz2", "application/x-bzip"), (".tar.xz", "application/x-xz"), + (".tar.Z", "application/x-compress"), ) for extension, mimetype in test_tuples: with self.subTest(ext=extension):