Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #126 -- HttpRequest now has a 'raw_post_data' attribute.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@478 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fcfb8edc153a3357529a86aff70ceb273859d7ca 1 parent bdcea2e
@adrianholovaty adrianholovaty authored
Showing with 20 additions and 5 deletions.
  1. +10 −2 django/core/handlers/modpython.py
  2. +10 −3 django/core/handlers/wsgi.py
View
12 django/core/handlers/modpython.py
@@ -23,9 +23,9 @@ def get_full_path(self):
def _load_post_and_files(self):
"Populates self._post and self._files"
if self._req.headers_in.has_key('content-type') and self._req.headers_in['content-type'].startswith('multipart'):
- self._post, self._files = httpwrappers.parse_file_upload(self._req.headers_in, self._req.read())
+ self._post, self._files = httpwrappers.parse_file_upload(self._req.headers_in, self.raw_post_data)
else:
- self._post, self._files = httpwrappers.QueryDict(self._req.read()), datastructures.MultiValueDict()
+ self._post, self._files = httpwrappers.QueryDict(self.raw_post_data), datastructures.MultiValueDict()
def _get_request(self):
if not hasattr(self, '_request'):
@@ -88,6 +88,13 @@ def _get_meta(self):
self._meta[key] = value
return self._meta
+ def _get_raw_post_data(self):
+ try:
+ return self._raw_post_data
+ except AttributeError:
+ self._raw_post_data = self._req.read()
+ return self._raw_post_data
+
def _load_session_and_user(self):
from django.models.auth import sessions
from django.conf.settings import AUTH_SESSION_COOKIE
@@ -122,6 +129,7 @@ def _set_user(self, user):
FILES = property(_get_files)
META = property(_get_meta)
REQUEST = property(_get_request)
+ raw_post_data = property(_get_raw_post_data)
session = property(_get_session, _set_session)
user = property(_get_user, _set_user)
View
13 django/core/handlers/wsgi.py
@@ -26,13 +26,12 @@ def get_full_path(self):
def _load_post_and_files(self):
# Populates self._post and self._files
if self.environ['REQUEST_METHOD'] == 'POST':
- post_data = self.environ['wsgi.input'].read(int(self.environ["CONTENT_LENGTH"]))
if self.environ.get('CONTENT_TYPE', '').startswith('multipart'):
header_dict = dict([(k, v) for k, v in self.environ.items() if k.startswith('HTTP_')])
header_dict['Content-Type'] = self.environ.get('CONTENT_TYPE', '')
- self._post, self._files = httpwrappers.parse_file_upload(header_dict, post_data)
+ self._post, self._files = httpwrappers.parse_file_upload(header_dict, self.raw_post_data)
else:
- self._post, self._files = httpwrappers.QueryDict(post_data), datastructures.MultiValueDict()
+ self._post, self._files = httpwrappers.QueryDict(self.raw_post_data), datastructures.MultiValueDict()
else:
self._post, self._files = httpwrappers.QueryDict(''), datastructures.MultiValueDict()
@@ -70,6 +69,13 @@ def _get_files(self):
self._load_post_and_files()
return self._files
+ def _get_raw_post_data(self):
+ try:
+ return self._raw_post_data
+ except AttributeError:
+ self._raw_post_data = self.environ['wsgi.input'].read(int(self.environ["CONTENT_LENGTH"]))
+ return self._raw_post_data
+
def _load_session_and_user(self):
from django.models.auth import sessions
from django.conf.settings import AUTH_SESSION_COOKIE
@@ -103,6 +109,7 @@ def _set_user(self, user):
COOKIES = property(_get_cookies, _set_cookies)
FILES = property(_get_files)
REQUEST = property(_get_request)
+ raw_post_data = property(_get_raw_post_data)
session = property(_get_session, _set_session)
user = property(_get_user, _set_user)
Please sign in to comment.
Something went wrong with that request. Please try again.