Robert Brewer committed bc3636c

Fix for #650 (PUT request with empty body/params ignored).

Comments (0)

Files changed (2)


     def process_body(self):
         """Convert request.rfile into request.params (or request.body). (Core)"""
+        if not self.headers.get("Content-Length", ""):
+            # No Content-Length header supplied (or it's 0).
+            # If we went ahead and called cgi.FieldStorage, it would hang,
+            # since it cannot determine when to stop reading from the socket.
+            # See
+            # See also
+            # Note also that we expect any HTTP server to have decoded
+            # any message-body that had a transfer-coding, and we expect
+            # the HTTP server to have supplied a Content-Length header
+            # which is valid for the decoded entity-body.
+            return
         # FieldStorage only recognizes POST, so fake it.
         methenv = {'REQUEST_METHOD': "POST"}
         if time.time() > self.time + self.timeout:
             self.timed_out = True


         if read_chunked:
             if not self.decode_chunked():
-        else:
-            cl = environ.get("CONTENT_LENGTH")
-            if method in ("POST", "PUT") and cl is None:
-                # No Content-Length header supplied. This will hang
-                # cgi.FieldStorage, since it cannot determine when to
-                # stop reading from the socket.
-                # See
-                self.simple_response("411 Length Required")
-                return
         # From PEP 333:
         # "Servers and gateways that implement HTTP 1.1 must provide
                     wsgikey = 'SSL_SERVER_%s_DN_%s' % (prefix, key)
                     self.ssl_environ[wsgikey] = value
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
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.