Ticket #3585 (closed defect: fixed)

Opened 21 months ago

Last modified 10 months ago

If the Content-Type of a request is "application/x-www-form-urlencoded", twisted.web.wsgi gives applications a zero-length input object

Reported by: wangchun Owned by: exarkun
Priority: normal Milestone:
Component: web Keywords:
Cc: mattc Branch: branches/wsgi-form-post-3585
Author: exarkun Launchpad Bug:

Description (last modified by exarkun) (diff)

Sometimes twisted.web.http.Request.requestReceived reads from the body object (Request.content) and parses the result into Request.args. Then it calls process. If a twisted.web.wsgi.WSGIResource is getting the request, it will be passed on as the wsgi.input in the environ to application code. This means that sometimes a wsgi application will get an already-read input and not be able to get the request body.

Attachments

3585.diff Download (0.5 KB) - added by wangchun 21 months ago.
3585_with_test.diff Download (1.2 KB) - added by mattc 20 months ago.
fix with test coverage

Change History

Changed 21 months ago by wangchun

Changed 21 months ago by exarkun

  • description modified (diff)
  • summary changed from [PATCH] Request.content should be rewinded to the beginning before Request.process is called to If the Content-Type of a request is "application/x-www-form-urlencoded", twisted.web.wsgi gives applications a zero-length input object

Adjusting summary and description to more directly describe the problem, rather than describing a possible solution. The old description was:


This causes problem with the recently added twisted.web.wsgi.

If a POST Request's Content-Type equals to 'application/x-www-form-urlencoded', calling environwsgi.input?.read(...) in a wsgi app will return empty string since it had been read before in the Twisted framework.

Patch attached.

Changed 20 months ago by mattc

  • cc mattc added

wangchun's fix seems fine to me. What's the next step?

Changed 20 months ago by exarkun

There need to be unit tests to go along with the fix.

Changed 20 months ago by mattc

fix with test coverage

Changed 20 months ago by mattc

  • keywords review added

Attached a fix with test coverage.

Changed 20 months ago by exarkun

  • owner jknight deleted

Changed 19 months ago by exarkun

  • owner set to exarkun
  • keywords review removed

The patch basically looks good to me. I've adjusted it a bit to deal with trivial coding standard issues and to be less specific in the prediction added to the unit tests, though.

Changed 19 months ago by exarkun

  • branch set to branches/wsgi-form-post-3585
  • branch_author set to exarkun

(In [26120]) Branching to 'wsgi-form-post-3585'

Changed 19 months ago by exarkun

(In [26121]) Apply slightly modified version of mattc's patch

refs #3585

Changed 19 months ago by exarkun

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

(In [26123]) Merge wsgi-form-post-3585

Author: mattc, exarkun Reviewer: exarkun Fixes: #3585

Ensure that Request.content is always positioned at the beginning of the file before calling the process method. This simplifies handling request bodies by making it never necessary to explicitly seek back to the beginning of the file.

Changed 10 months ago by exarkun

#4070 was a duplicate of this.

Note: See TracTickets for help on using tickets.