--
Ticket URL: <https://code.djangoproject.com/ticket/31550>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => needsinfo
* component: Uncategorized => HTTP handling
* type: Uncategorized => Cleanup/optimization
Comment:
Content-type depends on a platform. Jenkins doesn't report this issue on
Windows and Linux. What platform and Python version are you using?
--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:1>
Comment (by Yash Saini):
I am using Windows 10 and python 3.7.7.
--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:2>
Comment (by Carlton Gibson):
The failure doesn't reproduce for me on Windows with Python 3.7 or 3.8.
--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:3>
* status: closed => new
* resolution: needsinfo =>
Comment:
I think the test is incorrect in expecting `text/plain` instead of
`text/x-python` as the content type for a Python file
`test_file_response` in `tests/asgi/tests.py` fails for me as well.
{{{
(.venv) PS D:\source\django\tests> py runtests.py asgi.tests
...
======================================================================
FAIL: test_file_response (asgi.tests.ASGITest)
Makes sure that FileResponse works over ASGI.
----------------------------------------------------------------------
...
AssertionError: Items in the first set but not the second:
(b'Content-Type', b'text/x-python')
Items in the second set but not the first:
(b'Content-Type', b'text/plain')
}}}
My environment (Windows 10 Pro Build 20211):
{{{
>>> sys.platform
'win32'
>>> sys.getwindowsversion()
sys.getwindowsversion(major=10, minor=0, build=20211, platform=2,
service_pack='')
>>> sys.version
'3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit
(AMD64)]'
}}}
The `set_headers` method of `django.http.FileResponse` queries the content
type of the file on
[https://github.com/django/django/blob/master/django/http/response.py#L467
line 467]:
{{{
content_type, encoding = mimetypes.guess_type(filename)
}}}
On my machine, the above line sets `content_type` to `text/x-python`, but
[https://github.com/django/django/blob/master/tests/asgi/tests.py#L79 line
79] in the test file expects `text/plain` on Windows platforms:
{{{
self.assertEqual(
set(response_start['headers']),
{
(b'Content-Length', str(len(test_file_contents)).encode('ascii')),
(b'Content-Type', b'text/plain' if sys.platform == 'win32' else
b'text/x-python'), # line 79
(b'Content-Disposition', b'inline; filename="urls.py"'),
},
)
}}}
The test method is incorrect, but why doesn't this fail on Jenkins? Is
Jenkins running the tests on Windows 10 or an older version? The
[https://docs.python.org/3/library/mimetypes.html#mimetypes.guess_type
Python documentation] for `mimetypes.guess_type` doesn't shed much light,
specifically on whether the function returns `text/plain` for python files
on Windows platforms (perhaps previous versions).
--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:4>
* status: new => closed
* resolution: => needsinfo
Comment:
Hi Addison. This works for me. #32041 came up recently, which is related.
If you can dig-in and come up with some more information we can look into
it but short of a concrete analysis I'm not sure what we can do. What
action are we to take? (The line in the tests is as it is because this was
the behaviour we hit developing the feature…)
--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:5>
* status: closed => new
* has_patch: 0 => 1
* resolution: needsinfo =>
* stage: Unreviewed => Accepted
Comment:
This has come up again with a [https://github.com/django/django/pull/13633
PR adjusting the test case to pass with either mimetype].
--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:6>
* owner: nobody => chrisxkeith
* needs_better_patch: 0 => 1
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:7>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:8>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:9>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"76181308fb02e67794d0cc1471766a5d7e4c877e" 7618130]:
{{{
#!CommitTicketReference repository=""
revision="76181308fb02e67794d0cc1471766a5d7e4c877e"
Fixed #31550 -- Adjusted ASGI test_file_response for various Windows
content types.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:10>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"5dec57a6fc5a41bdfe1e881bfd364d7ae1c67b5e" 5dec57a6]:
{{{
#!CommitTicketReference repository=""
revision="5dec57a6fc5a41bdfe1e881bfd364d7ae1c67b5e"
[3.1.x] Fixed #31550 -- Adjusted ASGI test_file_response for various
Windows content types.
Backport of 76181308fb02e67794d0cc1471766a5d7e4c877e from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:11>