diff --git a/django/http/request.py b/django/http/request.py
index 6bce1f7..1d10042 100644
a
|
b
|
class HttpRequest(object):
|
224 | 224 | return |
225 | 225 | if self._read_started and not hasattr(self, '_body'): |
226 | 226 | self._mark_post_parse_error() |
227 | | return |
| 227 | raise RawPostDataException("You cannot parse POST after reading from request's data stream") |
228 | 228 | |
229 | 229 | if self.META.get('CONTENT_TYPE', '').startswith('multipart/form-data'): |
230 | 230 | if hasattr(self, '_body'): |
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
index 3cff5c2..14435a1 100644
a
|
b
|
All attributes should be considered read-only, unless stated otherwise below.
|
87 | 87 | from ``GET`` or ``POST``) will use the new ``encoding`` value. Useful if |
88 | 88 | you know the form data is not in the :setting:`DEFAULT_CHARSET` encoding. |
89 | 89 | |
| 90 | In case of "multipart/form-data" request, raw body is consumend and discarded on |
| 91 | first access to ```POST``` or ```FILES```, so you cannot use HttpRequest.encoding |
| 92 | to modify request anymore. In case you do, exception will be thrown on |
| 93 | any subsequent access to ```POST``` or ```FILES```. |
| 94 | |
90 | 95 | .. attribute:: HttpRequest.GET |
91 | 96 | |
92 | 97 | A dictionary-like object containing all given HTTP GET parameters. See the |
diff --git a/tests/requests/tests.py b/tests/requests/tests.py
index 175554e..068b0a9 100644
a
|
b
|
class RequestsTests(SimpleTestCase):
|
280 | 280 | 'wsgi.input': payload}) |
281 | 281 | self.assertEqual(request.read(2), b'na') |
282 | 282 | self.assertRaises(RawPostDataException, lambda: request.body) |
283 | | self.assertEqual(request.POST, {}) |
| 283 | self.assertRaises(RawPostDataException, lambda: request.POST) |
284 | 284 | |
285 | 285 | def test_non_ascii_POST(self): |
286 | 286 | payload = FakePayload(urlencode({'key': 'España'})) |
… |
… |
class RequestsTests(SimpleTestCase):
|
326 | 326 | self.assertEqual(request.POST, {'name': ['value']}) |
327 | 327 | self.assertRaises(RawPostDataException, lambda: request.body) |
328 | 328 | |
| 329 | def test_accessing_POST_after_POST_multipart_form_data_and_changing_encoding(self): |
| 330 | """ |
| 331 | Reading POST after parsing multipart/form-data and changing encoding is not allowed due to performance reasons. |
| 332 | """ |
| 333 | payload = FakePayload("\r\n".join([ |
| 334 | '--boundary', |
| 335 | 'Content-Disposition: form-data; name="name"', |
| 336 | '', |
| 337 | 'value', |
| 338 | '--boundary--' |
| 339 | ''])) |
| 340 | request = WSGIRequest({'REQUEST_METHOD': 'POST', |
| 341 | 'CONTENT_TYPE': 'multipart/form-data; boundary=boundary', |
| 342 | 'CONTENT_LENGTH': len(payload), |
| 343 | 'wsgi.input': payload}) |
| 344 | self.assertEqual(request.POST, {'name': ['value']}) |
| 345 | request.encoding = 'latin2' |
| 346 | self.assertRaises(RawPostDataException, lambda: request.POST) |
| 347 | |
329 | 348 | def test_body_after_POST_multipart_related(self): |
330 | 349 | """ |
331 | 350 | Reading body after parsing multipart that isn't form-data is allowed |