Ticket #5697 (closed defect: worksforme)
Ephemeral wsgi.input stream makes it nearly impossible for plugins to change URL structure
| Reported by: | Dave Abrahams <dave@…> | Owned by: | jonas |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | general | Version: | devel |
| Severity: | normal | Keywords: | |
| Cc: | daniel@… |
Description
See, for example, the TracForge project list.
Some information is lost as req.args is constructed, and all of that information needs to be reassembled exactly as-is for, e.g. file upload (which uses a multipart-formdata request), even though the plugin may not even be interested in touching it (as in the case of TracForge). Python gives us no facility for undoing the parsing of cgi.FieldStorage, so anyone attempting this sort of hook will have to repeat an extremely complicated series of steps; it would be better to capture the request in a string that can be reused.
The following simple patch remedies the problem:
-
api.py
old new 434 434 args = _RequestArgs() 435 435 436 436 fp = self.environ['wsgi.input'] 437 # We need to be able to read the data more than once. 438 from StringIO import StringIO 439 data = fp.read() 440 fp = StringIO(data) 441 self.environ['wsgi.input'] = StringIO(data) 437 442 438 443 # Avoid letting cgi.FieldStorage consume the input stream when the 439 444 # request does not contain form data


