#58 Drop jsonp decorator from the branches endpoint
Merged 7 years ago by pingou. Opened 7 years ago by pingou.

file modified
+17 -3
@@ -297,7 +297,6 @@ 

  

  

  @asyncio.coroutine

- @allows_jsonp

  def list_branches(request):

      ''' Return the list of all branches currently supported by mdapi

      '''
@@ -313,8 +312,23 @@ 

      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

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 pingou@pingoured.fr

2 new commits added

  • Drop the jsonp decorator from the branches endpoint and do it manually
  • Expose the upstream URL as present in the metadata in the JSON returned
7 years ago

This seems to be a repeat commit from another pull request. You might want to rebase this branch so it only contains the intended commit.

It would be good to document what doesn't work.

I recommend adding test coverage here. Test coverage would probably have helped detect the problem with the jsonp decorator, and can ensure the the function continues to work in the future.

LGTM.

I am not entirely sure what doesn't work I think it's to due with asyncio and coroutines, somehow this is returning an object instead of a generator.

I will add a note about this

This PR is based on the other one, once I merge the other one, this commit will be gone from this PR :)

rebased

7 years ago

rebased

7 years ago

Thanks for your review.

Pull-Request has been merged by pingou

7 years ago
Metadata