Loading django/http/__init__.py +2 −2 Original line number Diff line number Diff line from django.http.cookie import SimpleCookie, parse_cookie from django.http.request import (HttpRequest, QueryDict, UnreadablePostError, build_request_repr) from django.http.request import (HttpRequest, QueryDict, RawPostDataException, UnreadablePostError, build_request_repr) from django.http.response import (HttpResponse, StreamingHttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect, HttpResponseNotModified, HttpResponseBadRequest, HttpResponseForbidden, Loading django/http/request.py +10 −1 Original line number Diff line number Diff line Loading @@ -31,6 +31,15 @@ class UnreadablePostError(IOError): pass class RawPostDataException(Exception): """ You cannot access raw_post_data from a request that has multipart/* POST data if it has been accessed via POST, FILES, etc.. """ pass class HttpRequest(object): """A basic HTTP request.""" Loading Loading @@ -192,7 +201,7 @@ class HttpRequest(object): def body(self): if not hasattr(self, '_body'): if self._read_started: raise Exception("You cannot access body after reading from request's data stream") raise RawPostDataException("You cannot access body after reading from request's data stream") try: self._body = self.read() except IOError as e: Loading tests/requests/tests.py +4 −3 Original line number Diff line number Diff line Loading @@ -12,7 +12,8 @@ from django.db import connection, connections, DEFAULT_DB_ALIAS from django.core import signals from django.core.exceptions import SuspiciousOperation from django.core.handlers.wsgi import WSGIRequest, LimitedStream from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_repr, UnreadablePostError from django.http import (HttpRequest, HttpResponse, parse_cookie, build_request_repr, UnreadablePostError, RawPostDataException) from django.test import SimpleTestCase, TransactionTestCase from django.test.client import FakePayload from django.test.utils import override_settings, str_prefix Loading Loading @@ -263,7 +264,7 @@ class RequestsTests(SimpleTestCase): 'CONTENT_LENGTH': len(payload), 'wsgi.input': payload}) self.assertEqual(request.read(2), b'na') self.assertRaises(Exception, lambda: request.body) self.assertRaises(RawPostDataException, lambda: request.body) self.assertEqual(request.POST, {}) def test_non_ascii_POST(self): Loading Loading @@ -308,7 +309,7 @@ class RequestsTests(SimpleTestCase): 'CONTENT_LENGTH': len(payload), 'wsgi.input': payload}) self.assertEqual(request.POST, {'name': ['value']}) self.assertRaises(Exception, lambda: request.body) self.assertRaises(RawPostDataException, lambda: request.body) def test_body_after_POST_multipart_related(self): """ Loading Loading
django/http/__init__.py +2 −2 Original line number Diff line number Diff line from django.http.cookie import SimpleCookie, parse_cookie from django.http.request import (HttpRequest, QueryDict, UnreadablePostError, build_request_repr) from django.http.request import (HttpRequest, QueryDict, RawPostDataException, UnreadablePostError, build_request_repr) from django.http.response import (HttpResponse, StreamingHttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect, HttpResponseNotModified, HttpResponseBadRequest, HttpResponseForbidden, Loading
django/http/request.py +10 −1 Original line number Diff line number Diff line Loading @@ -31,6 +31,15 @@ class UnreadablePostError(IOError): pass class RawPostDataException(Exception): """ You cannot access raw_post_data from a request that has multipart/* POST data if it has been accessed via POST, FILES, etc.. """ pass class HttpRequest(object): """A basic HTTP request.""" Loading Loading @@ -192,7 +201,7 @@ class HttpRequest(object): def body(self): if not hasattr(self, '_body'): if self._read_started: raise Exception("You cannot access body after reading from request's data stream") raise RawPostDataException("You cannot access body after reading from request's data stream") try: self._body = self.read() except IOError as e: Loading
tests/requests/tests.py +4 −3 Original line number Diff line number Diff line Loading @@ -12,7 +12,8 @@ from django.db import connection, connections, DEFAULT_DB_ALIAS from django.core import signals from django.core.exceptions import SuspiciousOperation from django.core.handlers.wsgi import WSGIRequest, LimitedStream from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_repr, UnreadablePostError from django.http import (HttpRequest, HttpResponse, parse_cookie, build_request_repr, UnreadablePostError, RawPostDataException) from django.test import SimpleTestCase, TransactionTestCase from django.test.client import FakePayload from django.test.utils import override_settings, str_prefix Loading Loading @@ -263,7 +264,7 @@ class RequestsTests(SimpleTestCase): 'CONTENT_LENGTH': len(payload), 'wsgi.input': payload}) self.assertEqual(request.read(2), b'na') self.assertRaises(Exception, lambda: request.body) self.assertRaises(RawPostDataException, lambda: request.body) self.assertEqual(request.POST, {}) def test_non_ascii_POST(self): Loading Loading @@ -308,7 +309,7 @@ class RequestsTests(SimpleTestCase): 'CONTENT_LENGTH': len(payload), 'wsgi.input': payload}) self.assertEqual(request.POST, {'name': ['value']}) self.assertRaises(Exception, lambda: request.body) self.assertRaises(RawPostDataException, lambda: request.body) def test_body_after_POST_multipart_related(self): """ Loading