misc: use application/javascript as content type for jsonp request (#14683)

This commit is contained in:
Thomas NOËL 2017-01-19 16:59:27 +01:00
parent 57cf20cb2c
commit 884fdd0782
2 changed files with 7 additions and 1 deletions

View File

@ -400,7 +400,6 @@ def asset_delete(request):
def menu_json(request):
response = HttpResponse(content_type='application/json')
if getattr(settings, 'TEMPLATE_VARS', {}).get('site_title'):
label = _('Editing %(site_title)s') % getattr(settings, 'TEMPLATE_VARS')
else:
@ -409,9 +408,12 @@ def menu_json(request):
'slug': 'portal',
'url': request.build_absolute_uri(reverse('combo-manager-homepage'))
}])
content_type = 'application/json'
for variable in ('jsonpCallback', 'callback'):
if variable in request.GET:
json_str = '%s(%s);' % (request.GET[variable], json_str)
content_type = 'application/javascript'
break
response = HttpResponse(content_type=content_type)
response.write(json_str)
return response

View File

@ -380,3 +380,7 @@ def test_menu_json(app, admin_user):
resp = app.get('/manage/menu.json')
assert resp.headers['content-type'] == 'application/json'
assert resp.json[0]['label'] == 'Content Management'
resp = app.get('/manage/menu.json?callback=fooBar')
assert resp.headers['content-type'] == 'application/javascript'
assert resp.content.startswith('fooBar([{"')