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

Ticket #819 (defect)

Opened 4 months ago

Last modified 4 months ago

Request body not consumed on error when max_request_body_size is 0

Status: closed (fixed)

Reported by: davidf@sjsoft.com Assigned to: fumanchu
Priority: high Milestone: 3.1
Component: wsgiserver Keywords: HTTP request connection
Cc:

[1786] implemented consuming the request body if a CONTENT_LENGTH was given and an error was raised (see #786).

However, in the default case when max_request_body_size is 0, the maxlen of the rfile gets set to 0 and so the remaining body is not read. This has the effect of lines in a POST body being treated as subsequent requests...

I have a test and a fix for this, which I will attach...

Attachments

python-cherrypy-wsgi-819-test.patch (2.0 kB) - added by davidf@sjsoft.com on 05/23/08 02:37:21.
Test what happens when POST raises an error before body is read
python-cherrypy-wsgi-819-fix.patch (0.5 kB) - added by davidf@sjsoft.com on 05/23/08 02:45:50.
Patch to ensure we read the message body if no maximum length is set

Change History

05/23/08 02:37:21: Modified by davidf@sjsoft.com

  • attachment python-cherrypy-wsgi-819-test.patch added.

Test what happens when POST raises an error before body is read

05/23/08 02:44:58: Modified by davidf@sjsoft.com

The attached test gives the following traceback when run on unmodified 3.1.0rc1:

[root@localhost test]# python test_wsgiapps.py
....
    ERROR: 'Hello world' not in body
    Show: [B]ody [H]eaders [S]tatus [U]RL; [I]gnore, [R]aise, or sys.e[X]it >>  R
F
======================================================================
FAIL: test_07_post_error (__main__.WSGIGraftTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/cherrypy/test/webtest.py", line 278, in __call__
    testMethod()
  File "test_wsgiapps.py", line 124, in test_07_post_error
    self.assertInBody('Hello world')
  File "/usr/lib/python2.5/site-packages/cherrypy/test/webtest.py", line 401, in assertInBody
    self._handlewebError(msg)
  File "/usr/lib/python2.5/site-packages/cherrypy/test/webtest.py", line 253, in _handlewebError
    raise self.failureException(msg)
AssertionError: 'Hello world' not in body

----------------------------------------------------------------------
Ran 5 tests in 2.538s

FAILED (failures=1)

This is because the POSTed body is being read as the next request.

Simple patch to fix this coming next...

05/23/08 02:45:50: Modified by davidf@sjsoft.com

  • attachment python-cherrypy-wsgi-819-fix.patch added.

Patch to ensure we read the message body if no maximum length is set

05/23/08 02:46:33: Modified by davidf@sjsoft.com

Tests all pass when that patch is included - could this be included for 3.1.0 final?

05/23/08 02:55:30: Modified by guest

  • component changed from CherryPy code to wsgiserver.

05/24/08 13:27:07: Modified by fumanchu

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [1968]. Excellent analysis! Thanks for the patch and test. I moved your test to the same place that tested the previous readall_or_close behavior, but I still appreciate the effort to integrate the test into the existing suite. :)

Hosted by WebFaction

Log in as guest/cpguest to create tickets