Ticket #12522: raw_post.diff

File raw_post.diff, 3.4 KB (added by Maxim Ivanov, 15 years ago)

Fix patch + regression tests on WSGI handler

  • 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  
    11import os
    22from pprint import pformat
     3try:
     4    from cStringIO import StringIO
     5except ImportError:
     6    from StringIO import StringIO
    37
    48from django import http
    59from django.core import signals
    class ModPythonRequest(http.HttpRequest):  
    8286            return
    8387
    8488        if 'content-type' in self._req.headers_in and self._req.headers_in['content-type'].startswith('multipart'):
    85             self._raw_post_data = ''
    8689            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))
    8891            except:
    8992                # See django.core.handlers.wsgi.WSGIHandler for an explanation
    9093                # 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):  
    132132        # Populates self._post and self._files
    133133        if self.method == 'POST':
    134134            if self.environ.get('CONTENT_TYPE', '').startswith('multipart'):
    135                 self._raw_post_data = ''
     135                body = StringIO(self.raw_post_data)
    136136                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)
    138138                except:
    139139                    # An error occured while parsing POST data.  Since when
    140140                    # 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  
    4444>>> request.path = ''
    4545>>> print request.build_absolute_uri(location="/path/with:colons")
    4646http://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
     55testvalue
     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
     64True
    4765"""
     66
Back to Top