From ec6190d98cb1d0e8d560f9a787c01d1726692e82 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Tue, 12 Jan 2016 02:07:41 +0000 Subject: [PATCH] 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. --- CHANGES.md | 1 + sickbeard/webapi.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c79deac6..538e53b3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/sickbeard/webapi.py b/sickbeard/webapi.py index 8d3f2d05..ec2aaf4b 100644 --- a/sickbeard/webapi.py +++ b/sickbeard/webapi.py @@ -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 """