Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Adrian Holovaty authored August 10, 2005
12  django/core/handlers/modpython.py
@@ -23,9 +23,9 @@ def get_full_path(self):
23 23
     def _load_post_and_files(self):
24 24
         "Populates self._post and self._files"
25 25
         if self._req.headers_in.has_key('content-type') and self._req.headers_in['content-type'].startswith('multipart'):
26  
-            self._post, self._files = httpwrappers.parse_file_upload(self._req.headers_in, self._req.read())
  26
+            self._post, self._files = httpwrappers.parse_file_upload(self._req.headers_in, self.raw_post_data)
27 27
         else:
28  
-            self._post, self._files = httpwrappers.QueryDict(self._req.read()), datastructures.MultiValueDict()
  28
+            self._post, self._files = httpwrappers.QueryDict(self.raw_post_data), datastructures.MultiValueDict()
29 29
 
30 30
     def _get_request(self):
31 31
         if not hasattr(self, '_request'):
@@ -88,6 +88,13 @@ def _get_meta(self):
88 88
                 self._meta[key] = value
89 89
         return self._meta
90 90
 
  91
+    def _get_raw_post_data(self):
  92
+        try:
  93
+            return self._raw_post_data
  94
+        except AttributeError:
  95
+            self._raw_post_data = self._req.read()
  96
+            return self._raw_post_data
  97
+
91 98
     def _load_session_and_user(self):
92 99
         from django.models.auth import sessions
93 100
         from django.conf.settings import AUTH_SESSION_COOKIE
@@ -122,6 +129,7 @@ def _set_user(self, user):
122 129
     FILES = property(_get_files)
123 130
     META = property(_get_meta)
124 131
     REQUEST = property(_get_request)
  132
+    raw_post_data = property(_get_raw_post_data)
125 133
     session = property(_get_session, _set_session)
126 134
     user = property(_get_user, _set_user)
127 135
 
13  django/core/handlers/wsgi.py
@@ -26,13 +26,12 @@ def get_full_path(self):
26 26
     def _load_post_and_files(self):
27 27
         # Populates self._post and self._files
28 28
         if self.environ['REQUEST_METHOD'] == 'POST':
29  
-            post_data = self.environ['wsgi.input'].read(int(self.environ["CONTENT_LENGTH"]))
30 29
             if self.environ.get('CONTENT_TYPE', '').startswith('multipart'):
31 30
                 header_dict = dict([(k, v) for k, v in self.environ.items() if k.startswith('HTTP_')])
32 31
                 header_dict['Content-Type'] = self.environ.get('CONTENT_TYPE', '')
33  
-                self._post, self._files = httpwrappers.parse_file_upload(header_dict, post_data)
  32
+                self._post, self._files = httpwrappers.parse_file_upload(header_dict, self.raw_post_data)
34 33
             else:
35  
-                self._post, self._files = httpwrappers.QueryDict(post_data), datastructures.MultiValueDict()
  34
+                self._post, self._files = httpwrappers.QueryDict(self.raw_post_data), datastructures.MultiValueDict()
36 35
         else:
37 36
             self._post, self._files = httpwrappers.QueryDict(''), datastructures.MultiValueDict()
38 37
 
@@ -70,6 +69,13 @@ def _get_files(self):
70 69
             self._load_post_and_files()
71 70
         return self._files
72 71
 
  72
+    def _get_raw_post_data(self):
  73
+        try:
  74
+            return self._raw_post_data
  75
+        except AttributeError:
  76
+            self._raw_post_data = self.environ['wsgi.input'].read(int(self.environ["CONTENT_LENGTH"]))
  77
+            return self._raw_post_data
  78
+
73 79
     def _load_session_and_user(self):
74 80
         from django.models.auth import sessions
75 81
         from django.conf.settings import AUTH_SESSION_COOKIE
@@ -103,6 +109,7 @@ def _set_user(self, user):
103 109
     COOKIES = property(_get_cookies, _set_cookies)
104 110
     FILES = property(_get_files)
105 111
     REQUEST = property(_get_request)
  112
+    raw_post_data = property(_get_raw_post_data)
106 113
     session = property(_get_session, _set_session)
107 114
     user = property(_get_user, _set_user)
108 115
 

0 notes on commit fcfb8ed

Please sign in to comment.
Something went wrong with that request. Please try again.