Opened 20 months ago

Last modified 20 months ago

#34404 closed Cleanup/optimization

Incorrect documentation about content type set by FileResponse object — at Version 2

Reported by: chamalsl Owned by: nobody
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 (2)

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.

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