Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #811 (defect)

Opened 2 months ago

Last modified 6 days ago

CP WSGI requires a full read of request body

Status: closed (worksforme)

Reported by: guest Assigned to: fumanchu
Priority: normal Milestone: 3.1
Component: wsgiserver Keywords:
Cc: pstradomski@gmail.com

If a request body is not read then it is prepended to the REQUEST_METHOD of the following request.

#!/usr/bin/python
# encoding: utf-8

import cherrypy.wsgiserver as wsgiserver
from webob import Request, Response

def wsgi_app(environ, start_response):
    print environ['REQUEST_METHOD']
    request = Request(environ)
    
    print request.method
    
    # FIXME: force a read of the request body (workaround for CherryPy)
    # request.body
    
    response = Response(body="<html><body><form method='post'><input name='aaa' /></form></body></html>")
    return response(environ, start_response)


server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8080), wsgi_app)

if __name__ == '__main__':
    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()

The first POST is OK, the second one has the body of the previous post prepended to the request method:

Console output: {{{GET GET POST POST aaa=aaaaaPOST aaa=aaaaaPOST }}}

Forcing a full read of the body gives a workaround for the problem.

(rev-1956 and 3.1.0-beta3)

Change History

05/06/08 15:28:40: Modified by guest

  • cc set to pstradomski@gmail.com.

06/06/08 16:56:51: Modified by guest

  • component changed from CherryPy code to wsgiserver.

06/29/08 14:31:32: Modified by fumanchu

  • status changed from new to closed.
  • resolution set to worksforme.
  • milestone set to 3.1.

Hmmm. Your demo works fine for me with CP trunk and webob trunk. Since [1786] HTTPRequest.send_headers has said:

if (not self.close_connection) and (not self.chunked_read):
    # Read any remaining request body data on the socket.

I wonder how you're avoiding that. It's probably not that close_connection is True, because in that case the second request would be on its own conn. Are you doing chunked reads? That seems highly unlikely, but even if you were, wsgiserver currently reads the entire body into a StringIO before calling the app. I'm baffled.

Hosted by WebFaction

Log in as guest/cpguest to create tickets