Opened 20 months ago

Closed 20 months ago

Last modified 20 months ago

#34404 closed Cleanup/optimization (fixed)

Incorrect documentation about content type set by FileResponse object

Reported by: chamalsl Owned by: Ayush Bisht
Component: Documentation Version: 4.1
Severity: Normal Keywords:
Cc: chamalsl Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Mariusz Felisiak)

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.

Change History (7)

comment:1 by chamalsl, 20 months ago

Cc: chamalsl added

comment:2 by Mariusz Felisiak, 20 months ago

Description: modified (diff)
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

Thanks for the report.

comment:3 by Ayush Bisht, 20 months ago

Owner: changed from nobody to Ayush Bisht
Status: newassigned

comment:4 by Mariusz Felisiak, 20 months ago

Easy pickings: set
Has patch: set
Patch needs improvement: set

comment:5 by Mariusz Felisiak, 20 months ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 20 months ago

Resolution: fixed
Status: assignedclosed

In fc266b69:

Fixed #34404 -- Clarified how FileResponse set Content-Type header.

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 20 months ago

In eff2ba3f:

[4.2.x] Fixed #34404 -- Clarified how FileResponse set Content-Type header.

Backport of fc266b694b9129e44b597d8a56927ee13fdac358 from main

Note: See TracTickets for help on using tickets.
Back to Top