Opened 16 years ago

Closed 11 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)

wsgi.py.diff (684 bytes ) - added by Gruffudd Williams 16 years ago.
Temporary fix
9054-modpython-workaround.diff (1.2 KB ) - added by chris chamberlin 15 years ago.
partial hack for mod_python handler

Download all attachments as: .zip

Change History (16)

by Gruffudd Williams, 16 years ago

Attachment: wsgi.py.diff added

Temporary fix

comment:1 by Gruffudd Williams, 16 years ago

Has patch: set

comment:2 by chris chamberlin, 15 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 chris chamberlin, 15 years ago

partial hack for mod_python handler

comment:3 by chris chamberlin , 15 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 mristroph, 15 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 Eric Holscher, 15 years ago

Triage Stage: UnreviewedAccepted

Marking as accepted since it has been reported by multiple people.

comment:6 by Ville Säävuori, 15 years ago

Cc: ville@… added

This is possibly related to #3211.

comment:7 by Peter Bengtsson, 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 Ramiro Morales, 13 years ago

Needs tests: set
Patch needs improvement: set

Needs tests and patch most surely needs updating.

comment:9 by Luke Plant, 13 years ago

Severity: Normal
Type: Bug

comment:10 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:11 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:12 by senko, 11 years ago

Owner: changed from nobody to senko
Status: newassigned

comment:13 by senko, 11 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 Aymeric Augustin <aymeric.augustin@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 566e284c565a9ea95d81756c6b1f94dfa63fc61b:

Added test for multipart, non form-data POST.

Closes #9054. The bug itself is no longer present.

Note: See TracTickets for help on using tickets.
Back to Top