Change API response header for JSON content type and the return of JSONP data.

The API should return application/json Content-Type for JSON data instead of application/html.
This commit is contained in:
JackDandy 2016-01-12 02:07:41 +00:00
parent 53e4a0ecaa
commit ec6190d98c
2 changed files with 6 additions and 5 deletions

View file

@ -4,6 +4,7 @@
* Update xmltodict library 0.9.2 (579a005) to 0.9.2 (eac0031)
* Update Tornado Web Server 4.3.dev1 (1b6157d) to 4.4.dev1 (c2b4d05)
* Update change to suppress reporting of Tornado exception error 1 to updated package (ref:hacks.txt)
* Change API response header for JSON content type and the return of JSONP data
### 0.11.0 (2016-01-10 22:30:00 UTC)

View file

@ -135,19 +135,19 @@ class Api(webserve.BaseHandler):
self.finish(outputCallback(outDict))
def _out_as_json(self, dict):
self.set_header('Content-Type', 'application/json')
self.set_header('Content-Type', 'application/json; charset=UTF-8')
try:
out = json.dumps(dict, indent=self.intent, sort_keys=True)
if 'jsonp' in self.request.query_arguments:
out = self.request.arguments['jsonp'] + '(' + out + ');' # wrap with JSONP call if requested
callback = self.get_query_argument('callback', None) or self.get_query_argument('jsonp', None)
if None is not callback:
out = '%s(%s);' % (callback, out) # wrap with JSONP call if requested
except Exception as e: # if we fail to generate the output fake an error
logger.log(u'API :: ' + traceback.format_exc(), logger.DEBUG)
out = '{"result":"' + result_type_map[RESULT_ERROR] + '", "message": "error while composing output: "' + ex(
e) + '"}'
tornado_write_hack_dict = {'unwrap_json': out}
return tornado_write_hack_dict
return out
def _grand_access(self, realKey, apiKey, args, kwargs):
""" validate api key and log result """