From cff48a185abf457c672d2520eb0c9415f6ab3f8e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 02 2017 10:20:23 +0000 Subject: Drop the jsonp decorator from the branches endpoint and do it manually The decorator to add support for JSONP doesn't seem to handle this endpoint, so we just remove it and added back JSONP support manually. Fixes https://pagure.io/mdapi/issue/55 Signed-off-by: Pierre-Yves Chibon --- diff --git a/mdapi/__init__.py b/mdapi/__init__.py index 3a5b9fb..e112738 100644 --- a/mdapi/__init__.py +++ b/mdapi/__init__.py @@ -297,7 +297,6 @@ def get_pkg_changelog(request): @asyncio.coroutine -@allows_jsonp def list_branches(request): ''' Return the list of all branches currently supported by mdapi ''' @@ -313,8 +312,23 @@ def list_branches(request): if pretty: args = dict(sort_keys=True, indent=4, separators=(',', ': ')) - return web.Response(body=json.dumps(output, **args).encode('utf-8'), - content_type='application/json') + response = web.Response(body=json.dumps(output, **args).encode('utf-8'), + content_type='application/json') + + # The decorator doesn't work for this endpoint, so do it manually here + # I am not really sure what doesn't work but it seems this endpoint is + # returning an object instead of the expected generator despite it being + # flagged as an asyncio coroutine + url_arg = parse_qs(request.query_string) + callback = url_arg.get('callback') + if callback and request.method == 'GET': + if isinstance(callback, list): + callback = callback[0] + response.mimetype = 'application/javascript' + response.text = '%s(%s);' % (callback, response.text) + + return response + @asyncio.coroutine @allows_jsonp