Opened 6 years ago

Closed 6 years ago

Last modified 5 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
(diff, github, buildbot, log)
Author: exarkun Launchpad Bug:

Description (last modified by exarkun)

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 6 years ago.
3585_with_test.diff (1.2 KB) - added by mattc 6 years ago.
fix with test coverage

Download all attachments as: .zip

Change History (13)

Changed 6 years ago by wangchun

comment:1 Changed 6 years 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.

comment:2 Changed 6 years ago by mattc

  • Cc mattc added

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

comment:3 Changed 6 years ago by exarkun

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

Changed 6 years ago by mattc

fix with test coverage

comment:4 Changed 6 years ago by mattc

  • Keywords review added

Attached a fix with test coverage.

comment:5 Changed 6 years ago by exarkun

  • Owner jknight deleted

comment:6 Changed 6 years ago by exarkun

  • Keywords review removed
  • Owner set to exarkun

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 6 years ago by exarkun

  • Author set to exarkun
  • Branch set to branches/wsgi-form-post-3585

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

comment:8 Changed 6 years ago by exarkun

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

refs #3585

comment:9 Changed 6 years ago by exarkun

  • Resolution set to fixed
  • Status changed from new to closed

(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 5 years ago by exarkun

#4070 was a duplicate of this.

comment:11 Changed 4 years ago by <automation>

  • Owner exarkun deleted
Note: See TracTickets for help on using tickets.