#9886: File-like interface for HttpRequest
------------------------------------+---------------------------------------
          Reporter:  isagalaev      |         Owner:  mtredinnick      
            Status:  new            |     Milestone:                   
         Component:  HTTP handling  |       Version:  1.0              
        Resolution:                 |      Keywords:  streaming request
             Stage:  Unreviewed     |     Has_patch:  1                
        Needs_docs:  1              |   Needs_tests:  1                
Needs_better_patch:  0              |  
------------------------------------+---------------------------------------
Changes (by isagalaev):

  * needs_better_patch:  => 0
  * has_patch:  0 => 1
  * needs_tests:  => 1
  * needs_docs:  => 1

Comment:

 Attached first patch for review. No changes to docs and tests yet, just
 code. Here's an overview of what and why has changed:

  * Both subclasses of HttpRequest "publish" their internal byte stream to
 {{{self._stream}}} which is then accessed from HttpRequest
  * Both subclasses also define a boolean {{{self._read_started}}} that is
 set later to True from HttpRequest methods to signal that reading from the
 stream has started and things like {{{raw_post_data}}} and {{{POST}}}
 aren't acessible
  * On the other hand, if {{{raw_post_data}}} is accessed before any
 attempt to read from the stream it's wrapped in StringIO and becomes
 {{{request._stream}}} itself.
  * Parsing of post data by upload handlers and reading of
 {{{raw_post_data}}} is extracted into HttpRequest because they were almost
 identical in both subclasses. I liked very much a comment in one of the
 copies of {{{_load_post_and_files}}} saying "read the proper comment in
 another file" :-)
  * core.handlers.wsgi now has a special wrapper class LimitedInput which
 takes a stream, content_length as its size limit and defines {{{read}}}
 and {{{readline}}} for it. Important thing is that it's used only when
 working with development server. It is needed because dev server passes as
 'wsgi.input' a pure socket._fileobject which hangs and waits forever when
 one tries to read past data that it has in it. I decided not to wrap
 proper production streams from mod_python and wsgi servers into
 LimitedInput to be able to use their own implementations of read and
 readline that I suspect to be more efficient. Both mod_python and flup are
 smart enough to close streams when read completely.

 Comments are welcome!

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9886#comment:1>
Django <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to