diff roundup/cgi/client.py @ 5608:5df309febe49

Path to support OPTIONS verb when using rest interface via roundup-server. Also make sure rest interface doesn't hang when processing OPTIONS, DELETE, PATCH which don't have a payload by creating a CONTENT_LENGTH of 0 if these verbs are used and CONTENT_LENGTH is missing.
author John Rouillard <rouilj@ieee.org>
date Fri, 08 Feb 2019 19:39:17 -0500
parents 79da1ca2f94b
children 0a8f0fddc2ae be99aa02c616
line wrap: on
line diff
--- a/roundup/cgi/client.py	Wed Jan 30 18:11:02 2019 +0100
+++ b/roundup/cgi/client.py	Fri Feb 08 19:39:17 2019 -0500
@@ -363,6 +363,18 @@
 
         # see if we need to re-parse the environment for the form (eg Zope)
         if form is None:
+            # cgi.FieldStorage doesn't special case OPTIONS, DELETE or
+            # PATCH verbs. They are processed like POST. So FieldStorage
+            # hangs on these verbs trying to read posted data that
+            # will never arrive.
+            # If not defined, set CONTENT_LENGTH to 0 so it doesn't
+            # hang reading the data.
+            if self.env['REQUEST_METHOD'] in ['OPTIONS', 'DELETE', 'PATCH']:
+                if 'CONTENT_LENGTH' not in self.env:
+                    self.env['CONTENT_LENGTH'] = 0
+                    logger.debug("Setting CONTENT_LENGTH to 0 for method: %s",
+                                self.env['REQUEST_METHOD'])
+
             self.form = cgi.FieldStorage(fp=request.rfile, environ=env)
             # In some case (e.g. content-type application/xml), cgi
             # will not parse anything. Fake a list property in this case

Roundup Issue Tracker: http://roundup-tracker.org/