Skip to content

Commit 139d6d4

Browse files
committed
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.
1 parent e2260f3 commit 139d6d4

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

roundup/cgi/wsgi_handler.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
from roundup.cgi import TranslationService
1515
from roundup.anypy import http_
1616
from roundup.anypy.strings import s2b, bs2b
17+
18+
from roundup.cgi.client import BinaryFieldStorage
19+
1720
BaseHTTPRequestHandler = http_.server.BaseHTTPRequestHandler
1821
DEFAULT_ERROR_MESSAGE = http_.server.DEFAULT_ERROR_MESSAGE
1922

@@ -69,21 +72,33 @@ def __call__(self, environ, start_response):
6972
request.headers = Headers(environ)
7073

7174
if environ ['REQUEST_METHOD'] == 'OPTIONS':
72-
code = 501
73-
message, explain = BaseHTTPRequestHandler.responses[code]
74-
request.start_response([('Content-Type', 'text/html'),
75-
('Connection', 'close')], code)
76-
request.wfile.write(s2b(DEFAULT_ERROR_MESSAGE % locals()))
77-
return []
78-
75+
if environ["PATH_INFO"][:5] == "/rest":
76+
# rest does support options
77+
# This I hope will result in self.form=None
78+
environ['CONTENT_LENGTH'] = 0
79+
else:
80+
code = 501
81+
message, explain = BaseHTTPRequestHandler.responses[code]
82+
request.start_response([('Content-Type', 'text/html'),
83+
('Connection', 'close')], code)
84+
request.wfile.write(s2b(DEFAULT_ERROR_MESSAGE % locals()))
85+
return []
86+
7987
tracker = roundup.instance.open(self.home, not self.debug)
8088

8189
# need to strip the leading '/'
8290
environ["PATH_INFO"] = environ["PATH_INFO"][1:]
8391
if request.timing:
8492
environ["CGI_SHOW_TIMING"] = request.timing
8593

86-
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
94+
form = BinaryFieldStorage(fp=environ['wsgi.input'], environ=environ)
95+
96+
if environ ['REQUEST_METHOD'] in ("OPTIONS", "DELETE"):
97+
# these methods have no data. When we init tracker.Client
98+
# set form to None and request.rfile to None to get a
99+
# properly initialized empty form.
100+
form = None
101+
request.rfile = None
87102

88103
client = tracker.Client(tracker, request, environ, form,
89104
request.translator)

0 commit comments

Comments
 (0)