#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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070186cfa2ff32-dd79dc40-65f2-43ca-8482-fb52e7c3cea6-000000%40eu-central-1.amazonses.com.

Reply via email to