Ticket #12522: raw_post.diff
File raw_post.diff, 3.4 KB (added by , 15 years ago) |
---|
-
django/core/handlers/modpython.py
diff --git a/django/core/handlers/modpython.py b/django/core/handlers/modpython.py index b1e3e17..6d1cc1e 100644
a b 1 1 import os 2 2 from pprint import pformat 3 try: 4 from cStringIO import StringIO 5 except ImportError: 6 from StringIO import StringIO 3 7 4 8 from django import http 5 9 from django.core import signals … … class ModPythonRequest(http.HttpRequest): 82 86 return 83 87 84 88 if 'content-type' in self._req.headers_in and self._req.headers_in['content-type'].startswith('multipart'): 85 self._raw_post_data = ''86 89 try: 87 self._post, self._files = self.parse_file_upload(self.META, self._req)90 self._post, self._files = self.parse_file_upload(self.META, StringIO(self.raw_post_data)) 88 91 except: 89 92 # See django.core.handlers.wsgi.WSGIHandler for an explanation 90 93 # of what's going on here. -
django/core/handlers/wsgi.py
diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py index 927b098..1f344e7 100644
a b class WSGIRequest(http.HttpRequest): 132 132 # Populates self._post and self._files 133 133 if self.method == 'POST': 134 134 if self.environ.get('CONTENT_TYPE', '').startswith('multipart'): 135 self._raw_post_data = ''135 body = StringIO(self.raw_post_data) 136 136 try: 137 self._post, self._files = self.parse_file_upload(self.META, self.environ['wsgi.input'])137 self._post, self._files = self.parse_file_upload(self.META, body) 138 138 except: 139 139 # An error occured while parsing POST data. Since when 140 140 # formatting the error the request handler might access -
tests/regressiontests/requests/tests.py
diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py index 1615a73..ae2ee4e 100644
a b https://www.example.com/asdf 44 44 >>> request.path = '' 45 45 >>> print request.build_absolute_uri(location="/path/with:colons") 46 46 http://www.example.com/path/with:colons 47 48 >>> from django.core.handlers.wsgi import WSGIRequest 49 >>> from django.test.client import MULTIPART_CONTENT, BOUNDARY, FakePayload, encode_multipart 50 >>> post_data = encode_multipart(BOUNDARY,dict(testkey="testvalue")) 51 >>> env = {'SERVER_PROTOCOL': 'HTTP/1.0','REQUEST_METHOD':'POST','wsgi.input':FakePayload(post_data),'CONTENT_TYPE':MULTIPART_CONTENT,'CONTENT_LENGTH':len(post_data)} 52 >>> req = WSGIRequest(env) 53 >>> nop = req.raw_post_data #acessing the raw data 54 >>> print req.POST['testkey'] #after acessing raw data POST still should be accesible 55 testvalue 56 57 >>> from django.core.handlers.wsgi import WSGIRequest 58 >>> from django.test.client import MULTIPART_CONTENT, BOUNDARY, FakePayload, encode_multipart 59 >>> post_data = encode_multipart(BOUNDARY,dict(testkey="testvalue")) 60 >>> env = {'SERVER_PROTOCOL': 'HTTP/1.0','REQUEST_METHOD':'POST','wsgi.input':FakePayload(post_data),'CONTENT_TYPE':MULTIPART_CONTENT,'CONTENT_LENGTH':len(post_data)} 61 >>> req = WSGIRequest(env) 62 >>> nop = req.POST['testkey'] #acessing POST keys 63 >>> len(req.raw_post_data) == len(post_data) #after that raw_post_data should still be non empty 64 True 47 65 """ 66