Commits

Robert Brewer committed ca94720

Moved request.body construction before config namespaces so 'request.body' config entries work.

Comments (0)

Files changed (2)

cherrypy/_cprequest.py

                     # Make a copy of the class hooks
                     self.hooks = self.__class__.hooks.copy()
                     self.toolmaps = {}
+                    
                     self.stage = 'get_resource'
                     self.get_resource(path_info)
+                    
+                    self.body = _cpreqbody.RequestBody(
+                        self.rfile, self.headers, request_params=self.params)
+                    
                     self.namespaces(self.config)
                     
                     self.stage = 'on_start_resource'
                     self.process_query_string()
                     
                     # Process the body
-                    self.body = _cpreqbody.RequestBody(
-                        self.rfile, self.headers, request_params=self.params)
                     if self.process_request_body:
                         if self.method not in self.methods_with_bodies:
                             self.process_request_body = False

cherrypy/test/test_config.py

             return self.db
         dbscheme.exposed = True
         
+        def plain(self, x):
+            return x
+        plain.exposed = True
+        plain._cp_config = {'request.body.attempt_charsets': ['utf-16']}
+        
         favicon_ico = cherrypy.tools.staticfile.handler(
                         filename=os.path.join(localDir, '../favicon.ico'))
     
         self.getPage("/favicon.ico")
         self.assertBody(open(os.path.join(localDir, "static/dirback.jpg"),
                              "rb").read())
-                             
+    
+    def test_request_body_namespace(self):
+        self.getPage("/plain", method='POST', headers=[
+            ('Content-Type', 'application/x-www-form-urlencoded'),
+            ('Content-Length', 13)],
+            body='\xff\xfex\x00=\xff\xfea\x00b\x00c\x00')
+        self.assertBody("abc")
+
+
 class VariableSubstitutionTests(unittest.TestCase):
     
     def test_config(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.