Opened 16 years ago
Closed 12 years ago
#9054 closed Bug (fixed)
request.raw_post_data is empty for multipart/related posts
Reported by: | Gruffudd Williams | Owned by: | senko |
---|---|---|---|
Component: | HTTP handling | Version: | 1.0 |
Severity: | Normal | Keywords: | multipart |
Cc: | ville@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
core/handlers/wsgi.py : request.raw_post_data is set to empty string if the request self.environ.get('CONTENT_TYPE', ).startswith('multipart').
This is probably ok for multipart/form-data (file upload), but I don't think it is correct for all multipart subtypes, specifically multipart/related, in which message parts should not be considered individually but rather as parts of an aggregate whole : http://en.wikipedia.org/wiki/MIME#Related
request.raw_post_data was set correctly in 0.97 but not in 1.0.
A specific example is posting a SOAP/ebXML multipart/related message.
Attachments (2)
Change History (16)
by , 16 years ago
Attachment: | wsgi.py.diff added |
---|
comment:1 by , 16 years ago
Has patch: | set |
---|
comment:2 by , 16 years ago
The mod_python handler has this same bug.
Another way this bug manifests itself: If I access the raw_post_data attribute first, the POST dict will be empty, even for multipart/form-data. As it stands, you can get your data either in POST or raw_post_data, but not both. Access to both is useful; I wrote middleware to mirror certain POST requests to another location, but it triggers this bug.
My inexpert assessment is that this bug results from changing django.http.HttpRequest.parse_file_upload() to take a file-like object (so it can read chunks), instead of taking the entire request content from raw_post_data as it was done pre-1.0.
An upload handler might help with a workaround?
by , 16 years ago
Attachment: | 9054-modpython-workaround.diff added |
---|
partial hack for mod_python handler
comment:3 by , 16 years ago
The patch attached just above seems to make it safe to peek at raw_post_data before the POST dict is generated, regardless of what the content-type is. It doesn't entirely fix the issue; you still can't access the attributes in reverse order; after you get POST, raw_post_data will be empty.
comment:4 by , 16 years ago
I just applied Chris' patch and it works as described. Thanks, Chris! I had same problem with the POST QueryDict being empty in views after accessing the raw_post_data in a decorator.
comment:5 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Marking as accepted since it has been reported by multiple people.
comment:7 by , 15 years ago
For what it's worth, I suffered too until I applied the wsgi.py patch and then I was able to have multipart/related SOAP posts posted to my app.
comment:8 by , 14 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
Needs tests and patch most surely needs updating.
comment:9 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:12 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:13 by , 12 years ago
The bug as described in description isn't present anymore, as http.request.HttpRequest._load_post_and_files
checks for multipart/form-data
explicitly.
Added a test proving the bug isn't there, pull is at: https://github.com/django/django/pull/1086
This doesn't address the related issue mentioned by Chris where you can't use both body (raw_post_data previously) and POST. My understanding from the code comments is that it's intentional, to avoid duplication of (potentially big) data in the memory (see comment in tests/requests/tests.py test_body_after_POST_multipart_form_data).
comment:14 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Temporary fix