diff roundup/cgi/wsgi_handler.py @ 5945:40f5b20d1e70

issue2551047: Fix crashes in DELETE, OPTIONS, PATCH The wsgi handler parses the form data. This is a partial patch that fixes some crashes and allows OPTIONS to be passed through the system. Before it was rejected with a 501 error. Other modes (cgi, roundup-server) use the code in the __init__method of the Client class in client.py to parse the input form. The Client code has been modified to parse and pass json input data. I think these changes have to be included in the wsgi handler as well.
author John Rouillard <rouilj@ieee.org>
date Tue, 22 Oct 2019 23:36:10 -0400
parents 883c9e90b403
children 82816000aef3
line wrap: on
line diff
--- a/roundup/cgi/wsgi_handler.py	Tue Oct 22 17:08:16 2019 -0400
+++ b/roundup/cgi/wsgi_handler.py	Tue Oct 22 23:36:10 2019 -0400
@@ -14,6 +14,9 @@
 from roundup.cgi import TranslationService
 from roundup.anypy import http_
 from roundup.anypy.strings import s2b, bs2b
+
+from roundup.cgi.client import BinaryFieldStorage
+
 BaseHTTPRequestHandler = http_.server.BaseHTTPRequestHandler
 DEFAULT_ERROR_MESSAGE = http_.server.DEFAULT_ERROR_MESSAGE
 
@@ -69,13 +72,18 @@
         request.headers = Headers(environ)
 
         if environ ['REQUEST_METHOD'] == 'OPTIONS':
-            code = 501
-            message, explain = BaseHTTPRequestHandler.responses[code]
-            request.start_response([('Content-Type', 'text/html'),
-                ('Connection', 'close')], code)
-            request.wfile.write(s2b(DEFAULT_ERROR_MESSAGE % locals()))
-            return []
-
+            if environ["PATH_INFO"][:5] == "/rest":
+                # rest does support options
+                # This I hope will result in self.form=None
+                environ['CONTENT_LENGTH'] = 0
+            else:
+                code = 501
+                message, explain = BaseHTTPRequestHandler.responses[code]
+                request.start_response([('Content-Type', 'text/html'),
+                                        ('Connection', 'close')], code)
+                request.wfile.write(s2b(DEFAULT_ERROR_MESSAGE % locals()))
+                return []
+        
         tracker = roundup.instance.open(self.home, not self.debug)
 
         # need to strip the leading '/'
@@ -83,7 +91,14 @@
         if request.timing:
             environ["CGI_SHOW_TIMING"] = request.timing
 
-        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
+        form = BinaryFieldStorage(fp=environ['wsgi.input'], environ=environ)
+
+        if environ ['REQUEST_METHOD'] in ("OPTIONS", "DELETE"):
+            # these methods have no data. When we init tracker.Client
+            # set form to None and request.rfile to None to get a
+            # properly initialized empty form.
+            form = None
+            request.rfile = None
 
         client = tracker.Client(tracker, request, environ, form,
             request.translator)

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