mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #8622: accessing POST after a POST handling exception no longer throws the server into an infinite loop. Thanks to vung for tracking this one down and fixing it.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8748 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -35,6 +35,7 @@ class ModPythonRequest(http.HttpRequest):
|
||||
# a common start character for URL patterns. So this is a little
|
||||
# naughty, but also pretty harmless.
|
||||
self.path_info = u'/'
|
||||
self._post_parse_error = False
|
||||
|
||||
def __repr__(self):
|
||||
# Since this is called as part of error handling, we need to be very
|
||||
@@ -43,10 +44,13 @@ class ModPythonRequest(http.HttpRequest):
|
||||
get = pformat(self.GET)
|
||||
except:
|
||||
get = '<could not parse>'
|
||||
try:
|
||||
post = pformat(self.POST)
|
||||
except:
|
||||
if self._post_parse_error:
|
||||
post = '<could not parse>'
|
||||
else:
|
||||
try:
|
||||
post = pformat(self.POST)
|
||||
except:
|
||||
post = '<could not parse>'
|
||||
try:
|
||||
cookies = pformat(self.COOKIES)
|
||||
except:
|
||||
@@ -73,7 +77,15 @@ class ModPythonRequest(http.HttpRequest):
|
||||
"Populates self._post and self._files"
|
||||
if 'content-type' in self._req.headers_in and self._req.headers_in['content-type'].startswith('multipart'):
|
||||
self._raw_post_data = ''
|
||||
self._post, self._files = self.parse_file_upload(self.META, self._req)
|
||||
try:
|
||||
self._post, self._files = self.parse_file_upload(self.META, self._req)
|
||||
except:
|
||||
# See django.core.handlers.wsgi.WSGIHandler for an explanation
|
||||
# of what's going on here.
|
||||
self._post = http.QueryDict('')
|
||||
self._files = datastructures.MultiValueDict()
|
||||
self._post_parse_error = True
|
||||
raise
|
||||
else:
|
||||
self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict()
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ class WSGIRequest(http.HttpRequest):
|
||||
self.META['PATH_INFO'] = path_info
|
||||
self.META['SCRIPT_NAME'] = script_name
|
||||
self.method = environ['REQUEST_METHOD'].upper()
|
||||
self._post_parse_error = False
|
||||
|
||||
def __repr__(self):
|
||||
# Since this is called as part of error handling, we need to be very
|
||||
@@ -100,10 +101,13 @@ class WSGIRequest(http.HttpRequest):
|
||||
get = pformat(self.GET)
|
||||
except:
|
||||
get = '<could not parse>'
|
||||
try:
|
||||
post = pformat(self.POST)
|
||||
except:
|
||||
if self._post_parse_error:
|
||||
post = '<could not parse>'
|
||||
else:
|
||||
try:
|
||||
post = pformat(self.POST)
|
||||
except:
|
||||
post = '<could not parse>'
|
||||
try:
|
||||
cookies = pformat(self.COOKIES)
|
||||
except:
|
||||
@@ -127,7 +131,20 @@ class WSGIRequest(http.HttpRequest):
|
||||
if self.method == 'POST':
|
||||
if self.environ.get('CONTENT_TYPE', '').startswith('multipart'):
|
||||
self._raw_post_data = ''
|
||||
self._post, self._files = self.parse_file_upload(self.META, self.environ['wsgi.input'])
|
||||
try:
|
||||
self._post, self._files = self.parse_file_upload(self.META, self.environ['wsgi.input'])
|
||||
except:
|
||||
# An error occured while parsing POST data. Since when
|
||||
# formatting the error the request handler might access
|
||||
# self.POST, set self._post and self._file to prevent
|
||||
# attempts to parse POST data again.
|
||||
self._post = http.QueryDict('')
|
||||
self._files = datastructures.MultiValueDict()
|
||||
# Mark that an error occured. This allows self.__repr__ to
|
||||
# be explicit about it instead of simply representing an
|
||||
# empty POST
|
||||
self._post_parse_error = True
|
||||
raise
|
||||
else:
|
||||
self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict()
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user