#14024: Application freezes on access to request.POST under
WSGIRequest+multipart
/form-data
---------------------------+------------------------------------------------
Reporter: zimnyx | Owner: nobody
Status: new | Milestone:
Component: HTTP handling | Version: SVN
Keywords: | Stage: Unreviewed
Has_patch: 1 |
---------------------------+------------------------------------------------
==How to reproduce==
1. manage.py runserver
2. send POST using multipart/form-data encoding
2. access request.raw_post_data, '''before request.POST was accessed''',
for example in first middleware's process_request()
3. access request.POST -- here application freezes
==Why it happens==
Accessing WSGIRequest.raw_post_data reads data from
WSGIRequest.environ['wsgi.input'] stream, which afterwards is exhausted.
Accessing request.POST calls WSGIRequest._load_post_and_files(), which
calls MultiPartParser.parse(), which tries to parse already exhausted
stream from WSGIRequest.environ['wsgi.input'].
== How to fix (fix is working, I don't claim it's a good way)==
{{{
--- core/handlers/wsgi.py (revision 13353)
+++ core/handlers/wsgi.py (local)
@@ -132,7 +132,7 @@
# Populates self._post and self._files
if self.method == 'POST':
if self.environ.get('CONTENT_TYPE',
'').startswith('multipart'):
- self._raw_post_data = ''
+ self._get_raw_post_data()
try:
self._post, self._files =
self.parse_file_upload(self.META, self.environ['wsgi.input'])
except:
@@ -204,7 +204,8 @@
safe_copyfileobj(self.environ['wsgi.input'], buf,
size=content_length)
self._raw_post_data = buf.getvalue()
- buf.close()
+ buf.seek(0)
+ self.environ['wsgi.input'] = buf
return self._raw_post_data
GET = property(_get_get, _set_get)
--
Ticket URL: <http://code.djangoproject.com/ticket/14024>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.