Robert Brewer avatar Robert Brewer committed e597882

New test for request payloads, and fix for chunked

Comments (0)

Files changed (2)

cheroot/server.py

                 self.buffer = self.buffer[remaining:]
             else:
                 data += self.buffer
+                self.buffer = EMPTY
     
     def readline(self, size=None):
         data = EMPTY

cheroot/test/test_core.py

 """Basic tests for the Cheroot server: request handling."""
 
-from cheroot._compat import ntob
+from cheroot._compat import ntob, HTTPConnection, HTTPSConnection
 from cheroot.test import helper
 
 
             def hello(self):
                 return "hello"
 
+            def echo(self, req, resp):
+                output = req.environ['wsgi.input'].read()
+                return output.decode("ISO-8859-1")
+
             def normal(self, req, resp):
                 return "normal"
             
         self.assertStatus(500)
         self.assertInBody("TypeError: WSGI response header key 2 is not of type str.")
 
+    def test_request_payload(self):
+        if self.scheme == "https":
+            c = HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
+        else:
+            c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
+        c.putrequest("POST", "/echo")
+        body = ntob("I am a request body")
+        c.putheader("Content-Length", len(body))
+        c.endheaders()
+        c.send(body)
+        response = c.getresponse()
+        self.body = response.read()
+        c.close()
+        self.status = str(response.status)
+        self.assertStatus(200)
+        self.assertBody(body)
+
+    def test_chunked_request_payload(self):
+        if self.scheme == "https":
+            c = HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
+        else:
+            c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
+        c.putrequest("POST", "/echo")
+        c.putheader("Transfer-Encoding", "chunked")
+        c.endheaders()
+        c.send(ntob("13\r\nI am a request body\r\n0\r\n\r\n"))
+        response = c.getresponse()
+        self.body = response.read()
+        c.close()
+        self.status = str(response.status)
+        self.assertStatus(200)
+        self.assertBody("I am a request body")
+
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.