[Django] #34404: Incorrect documentation about content type set by FileResponse object

12 views
Skip to first unread message

Django

unread,
Mar 10, 2023, 9:50:24 PM3/10/23
to django-...@googlegroups.com
#34404: Incorrect documentation about content type set by FileResponse object
-----------------------------------------+------------------------
Reporter: chamalsl | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Below is an excerpt from the Django document for FileResponse object.
Link: [https://docs.djangoproject.com/en/4.1/ref/request-response/]

"The Content-Length and Content-Type headers are automatically set when
they can be guessed from contents of open_file".

But code inside FileResponse object does not use contents of open_file to
guess content type.
It uses "mimetypes.guess_type()" method to determine content type.
"mimetypes.guess_type()" method uses file extension to to determine
content type.

So a file response object such as this will set the content type to
"text/html".

{{{
FileResponse(open('test.gif', 'rb'), filename="test.html")
}}}


Documentation should correctly mention how FileResponse object determine
content type.

--
Ticket URL: <https://code.djangoproject.com/ticket/34404>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 10, 2023, 9:51:14 PM3/10/23
to django-...@googlegroups.com
#34404: Incorrect documentation about content type set by FileResponse object
-------------------------------+--------------------------------------

Reporter: chamalsl | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by chamalsl):

* cc: chamalsl (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/34404#comment:1>

Django

unread,
Mar 11, 2023, 2:46:54 AM3/11/23
to django-...@googlegroups.com
#34404: Incorrect documentation about content type set by FileResponse object
--------------------------------------+------------------------------------
Reporter: chamalsl | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


Old description:

> Below is an excerpt from the Django document for FileResponse object.
> Link: [https://docs.djangoproject.com/en/4.1/ref/request-response/]
>
> "The Content-Length and Content-Type headers are automatically set when
> they can be guessed from contents of open_file".
>
> But code inside FileResponse object does not use contents of open_file to
> guess content type.
> It uses "mimetypes.guess_type()" method to determine content type.
> "mimetypes.guess_type()" method uses file extension to to determine
> content type.
>
> So a file response object such as this will set the content type to
> "text/html".
>
> {{{
> FileResponse(open('test.gif', 'rb'), filename="test.html")
> }}}
>

> Documentation should correctly mention how FileResponse object determine
> content type.

New description:

Below is an excerpt from the Django document for FileResponse object.
Link: [https://docs.djangoproject.com/en/4.1/ref/request-response/]

"The Content-Length and Content-Type headers are automatically set when
they can be guessed from contents of open_file".

But code inside FileResponse object does not use contents of open_file to
guess content type.
It uses "mimetypes.guess_type()" method to determine content type.
"mimetypes.guess_type()" method uses file extension to to determine
content type.

So a file response object such as this will set the content type to
"text/html".

{{{
FileResponse(open('test.gif', 'rb'), filename="test.html")
}}}


Documentation should correctly mention how FileResponse object determine
content type.

--

Comment:

Thanks for the report.

--
Ticket URL: <https://code.djangoproject.com/ticket/34404#comment:2>

Django

unread,
Mar 11, 2023, 11:33:04 AM3/11/23
to django-...@googlegroups.com
#34404: Incorrect documentation about content type set by FileResponse object
-------------------------------------+-------------------------------------
Reporter: chamalsl | Owner: Ayush
Type: | Bisht
Cleanup/optimization | Status: assigned

Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ayush Bisht):

* owner: nobody => Ayush Bisht
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34404#comment:3>

Django

unread,
Mar 15, 2023, 2:26:21 AM3/15/23
to django-...@googlegroups.com
#34404: Incorrect documentation about content type set by FileResponse object
-------------------------------------+-------------------------------------
Reporter: chamalsl | Owner: Ayush
Type: | Bisht
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* easy: 0 => 1


Comment:

[https://github.com/django/django/pull/16644 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/34404#comment:4>

Django

unread,
Mar 16, 2023, 12:33:31 AM3/16/23
to django-...@googlegroups.com
#34404: Incorrect documentation about content type set by FileResponse object
-------------------------------------+-------------------------------------
Reporter: chamalsl | Owner: Ayush
Type: | Bisht
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34404#comment:5>

Django

unread,
Mar 16, 2023, 3:31:30 AM3/16/23
to django-...@googlegroups.com
#34404: Incorrect documentation about content type set by FileResponse object
-------------------------------------+-------------------------------------
Reporter: chamalsl | Owner: Ayush
Type: | Bisht
Cleanup/optimization | Status: closed
Component: Documentation | Version: 4.1
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"fc266b694b9129e44b597d8a56927ee13fdac358" fc266b69]:
{{{
#!CommitTicketReference repository=""
revision="fc266b694b9129e44b597d8a56927ee13fdac358"
Fixed #34404 -- Clarified how FileResponse set Content-Type header.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34404#comment:6>

Django

unread,
Mar 16, 2023, 3:31:44 AM3/16/23
to django-...@googlegroups.com
#34404: Incorrect documentation about content type set by FileResponse object
-------------------------------------+-------------------------------------
Reporter: chamalsl | Owner: Ayush
Type: | Bisht
Cleanup/optimization | Status: closed
Component: Documentation | Version: 4.1
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"eff2ba3f8d2f172c64b9df08db8d188e11bae855" eff2ba3f]:
{{{
#!CommitTicketReference repository=""
revision="eff2ba3f8d2f172c64b9df08db8d188e11bae855"
[4.2.x] Fixed #34404 -- Clarified how FileResponse set Content-Type
header.

Backport of fc266b694b9129e44b597d8a56927ee13fdac358 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34404#comment:7>

Reply all
Reply to author
Forward
0 new messages