Ticket #3585 (closed defect: fixed )

Opened 1 year ago

Last modified 3 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 Assigned to: exarkun
Type: defect Priority: normal
Milestone: Component: web
Keywords: Cc: mattc
Branch: branches/wsgi-form-post-3585 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

3585.diff (0.5 kB) - added by wangchun 1 year ago.
3585_with_test.diff (1.2 kB) - added by mattc 1 year ago.
fix with test coverage

Change History

  2008-12-19 08:54:56+00:00 changed by wangchun

  • attachment 3585.diff added

  2008-12-19 14:45:08+00:00 changed by exarkun

  • description deleted
  • 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.

  2009-01-13 21:50:06+00:00 changed by mattc

  • cc set to mattc

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

  2009-01-14 15:52:37+00:00 changed by exarkun

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

  2009-01-17 17:50:58+00:00 changed by mattc

  • attachment 3585_with_test.diff added

fix with test coverage

  2009-01-17 17:52:06+00:00 changed by mattc

  • keywords set to review

Attached a fix with test coverage.

  2009-01-18 17:44:20+00:00 changed by exarkun

  • owner deleted

  2009-01-26 00:35:18+00:00 changed by exarkun

  • keywords deleted
  • 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.

  2009-01-26 00:36:48+00:00 changed by exarkun

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

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

  2009-01-26 00:37:33+00:00 changed by exarkun

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

refs #3585

  2009-01-26 01:53:18+00:00 changed 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.

  2009-11-06 16:45:31+00:00 changed by exarkun

#4070 was a duplicate of this.

Note: See TracTickets for help on using tickets.