Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#3585 defect closed fixed (fixed)

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:
Priority: normal Milestone:
Component: web Keywords:
Cc: mattc Branch: branches/wsgi-form-post-3585
branch-diff, diff-cov, branch-cov, buildbot
Author: exarkun

Description (last modified by Jean-Paul Calderone)

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 (2)

3585.diff (556 bytes) - added by wangchun 9 years ago.
3585_with_test.diff (1.2 KB) - added by mattc 9 years ago.
fix with test coverage

Download all attachments as: .zip

Change History (13)

Changed 9 years ago by wangchun

Attachment: 3585.diff added

comment:1 Changed 9 years ago by Jean-Paul Calderone

Description: modified (diff)
Summary: [PATCH] Request.content should be rewinded to the beginning before Request.process is calledIf 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.

comment:2 Changed 9 years ago by mattc

Cc: mattc added

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

comment:3 Changed 9 years ago by Jean-Paul Calderone

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

Changed 9 years ago by mattc

Attachment: 3585_with_test.diff added

fix with test coverage

comment:4 Changed 9 years ago by mattc

Keywords: review added

Attached a fix with test coverage.

comment:5 Changed 9 years ago by Jean-Paul Calderone

Owner: jknight deleted

comment:6 Changed 9 years ago by Jean-Paul Calderone

Keywords: review removed
Owner: set to Jean-Paul Calderone

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.

comment:7 Changed 9 years ago by Jean-Paul Calderone

Author: exarkun
Branch: branches/wsgi-form-post-3585

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

comment:8 Changed 9 years ago by Jean-Paul Calderone

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

refs #3585

comment:9 Changed 9 years ago by Jean-Paul Calderone

Resolution: fixed
Status: newclosed

(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.

comment:10 Changed 8 years ago by Jean-Paul Calderone

#4070 was a duplicate of this.

comment:11 Changed 7 years ago by <automation>

Owner: Jean-Paul Calderone deleted
Note: See TracTickets for help on using tickets.