Skip to content

Commit e4f7fa2

Browse files
committed
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.
1 parent db26b4e commit e4f7fa2

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Features:
3838
DELETE method. We also don't allow to DELETE a whole class. Python3
3939
support was also fixed and we have cherry-picked two patches from the
4040
bugs.python.org branch in the files affected by the REST-API changes.
41+
- Patch to client.py and roundup-server needed by REST-API
42+
code. Support OPTIONS verb and prevent hangs when processing a verb
43+
other than GET that doesn't have a payload. E.G. DELETE, PATCH or
44+
OPTIONS. Verbs like PUT and POST usually have payloads, so this
45+
patch doesn't touch processing of these methods. (John Rouillard)
4146

4247
Fixed:
4348

roundup/cgi/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,18 @@ def __init__(self, instance, request, env, form=None, translator=None):
363363

364364
# see if we need to re-parse the environment for the form (eg Zope)
365365
if form is None:
366+
# cgi.FieldStorage doesn't special case OPTIONS, DELETE or
367+
# PATCH verbs. They are processed like POST. So FieldStorage
368+
# hangs on these verbs trying to read posted data that
369+
# will never arrive.
370+
# If not defined, set CONTENT_LENGTH to 0 so it doesn't
371+
# hang reading the data.
372+
if self.env['REQUEST_METHOD'] in ['OPTIONS', 'DELETE', 'PATCH']:
373+
if 'CONTENT_LENGTH' not in self.env:
374+
self.env['CONTENT_LENGTH'] = 0
375+
logger.debug("Setting CONTENT_LENGTH to 0 for method: %s",
376+
self.env['REQUEST_METHOD'])
377+
366378
self.form = cgi.FieldStorage(fp=request.rfile, environ=env)
367379
# In some case (e.g. content-type application/xml), cgi
368380
# will not parse anything. Fake a list property in this case

roundup/scripts/roundup_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def run_cgi(self):
255255
print('EXCEPTION AT', ts)
256256
traceback.print_exc()
257257

258-
do_GET = do_POST = do_HEAD = do_PUT = do_DELETE = do_PATCH = run_cgi
258+
do_GET = do_POST = do_HEAD = do_PUT = do_DELETE = do_PATCH = do_OPTIONS = run_cgi
259259

260260
def index(self):
261261
''' Print up an index of the available trackers

0 commit comments

Comments
 (0)