Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added test for multipart, non form-data POST.

Closes #9054. The bug itself is no longer present.
  • Loading branch information...
commit 566e284c565a9ea95d81756c6b1f94dfa63fc61b 1 parent 7b85ef9
@senko senko authored aaugustin committed
Showing with 25 additions and 2 deletions.
  1. +25 −2 tests/requests/tests.py
View
27 tests/requests/tests.py
@@ -503,9 +503,9 @@ def test_alternate_charset_POST(self):
})
self.assertEqual(request.POST, {'key': ['España']})
- def test_body_after_POST_multipart(self):
+ def test_body_after_POST_multipart_form_data(self):
"""
- Reading body after parsing multipart is not allowed
+ Reading body after parsing multipart/form-data is not allowed
"""
# Because multipart is used for large amounts fo data i.e. file uploads,
# we don't want the data held in memory twice, and we don't want to
@@ -524,6 +524,29 @@ def test_body_after_POST_multipart(self):
self.assertEqual(request.POST, {'name': ['value']})
self.assertRaises(Exception, lambda: request.body)
+ def test_body_after_POST_multipart_related(self):
+ """
+ Reading body after parsing multipart that isn't form-data is allowed
+ """
+ # Ticket #9054
+ # There are cases in which the multipart data is related instead of
+ # being a binary upload, in which case it should still be accessible
+ # via body.
+ payload_data = "\r\n".join([
+ '--boundary',
+ 'Content-ID: id; name="name"',
+ '',
+ 'value',
+ '--boundary--'
+ ''])
+ payload = FakePayload(payload_data)
+ request = WSGIRequest({'REQUEST_METHOD': 'POST',
+ 'CONTENT_TYPE': 'multipart/related; boundary=boundary',
+ 'CONTENT_LENGTH': len(payload),
+ 'wsgi.input': payload})
+ self.assertEqual(request.POST, {})
+ self.assertEqual(request.body, payload_data)
+
def test_POST_multipart_with_content_length_zero(self):
"""
Multipart POST requests with Content-Length >= 0 are valid and need to be handled.
Please sign in to comment.
Something went wrong with that request. Please try again.