#30565: HttpResponseBase.close not called when using FileResponse / WSGI "file
wrapper" object
-------------------------------------+-------------------------------------
     Reporter:  Chris Jerdonek       |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  HTTP handling        |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  HttpResponse,        |             Triage Stage:
  streaming, StreamingHttpResponse   |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Chris Jerdonek):

 This might not be so elegant, but I confirmed that something like the
 following would work to have a `close()` on the "file wrapper" object as I
 described above. (You need to be careful to prevent infinite loops.) This
 could be done inside `FileResponse._set_streaming_content()`.

 {{{
 #!python
 response = FileResponse(stream)
 stream_close = stream.close

 class State:
     closing = False

 def file_wrapper_close():
     if State.closing:
         return

     State.closing = True

     stream_close()
     response.close()

 stream.close = file_wrapper_close
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30565#comment:8>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.b61aecabb9213d4d38bbd55d40c53521%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to