Opened 21 months ago

Last modified 20 months ago

#34404 closed Cleanup/optimization

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

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

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 (0)

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