Hi -I'm new to WSGI and CherryPy, and I'm trying to understand why CherryPyWSGIServer reads and discards the request body when my app first calls write(). The code snippet that does this is footnote [1] below from CherryPyWSGIServer (we're using 3.1.1, but the behavior looks the same in later versions).This is what's happening in our app, as best I can tell:1. an unchunked request comes in with a large body and a Content-Length header2. my app starts reading the body from wsgi.input3. at some arbitrary point mid-read, my app sends back a progress update to the client via write() (which is, as far as cherrypy is concerned, just some plain old bytes)4. cherrypy consumes the rest of the request body as part of sending the response headers before sending the data passed to write().I see the rationale in the CherryPyWSGIServer code, from the HTTP 1.1 spec -- "the server SHOULD NOT close the transport connection until it has read the entire request" -- but I don't see how that entails reading and discarding the request on the first write, since the connection isn't being closed at that point. Can anyone clarify/expand?If that rationale stands for whatever reason, how _should_ my app use write() without discarding the remainder of the request? Do I need to make sure the entire request body has been read before I ever call write()? Is that a WSGI expectation?Thanks a lot -Yash[1]if (not self.close_connection) and (not self.chunked_read):# Read any remaining request body data on the socket....
The short answer is: if you use yield and set "response.stream = True" for that URL, that tells all of CherryPy "don't buffer the output", in which case it behaves very much like write(). See http://docs.cherrypy.org/stable/progguide/streaming.html
Robert Brewer
--
You received this message because you are subscribed to the Google Groups
"cherrypy-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cherrypy-users/-/Tt3Zg6vkh9sJ.
To post to this group, send email to cherryp...@googlegroups.com.
To unsubscribe from this group, send email to
cherrypy-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en.