mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-07 10:33:38 +00:00
Merge pull request #146 from JackDandy/feature/FixAPI_JSON_Response
Fix API response header for JSON content type and the return of JSONP data
This commit is contained in:
commit
4d6543b73a
4 changed files with 14 additions and 6 deletions
|
@ -73,7 +73,7 @@
|
||||||
* Fix dropdown confirm dialogs for restart and shutdown
|
* Fix dropdown confirm dialogs for restart and shutdown
|
||||||
* Fix parsing utf8 data from tvdb and tvrage
|
* Fix parsing utf8 data from tvdb and tvrage
|
||||||
* Fix display show status and subtitle searches to use new column class names
|
* Fix display show status and subtitle searches to use new column class names
|
||||||
|
* Fix API response header for JSON content type and the return of JSONP data
|
||||||
|
|
||||||
### 0.2.1 (2014-10-22 06:41:00 UTC)
|
### 0.2.1 (2014-10-22 06:41:00 UTC)
|
||||||
|
|
||||||
|
|
3
HACKS.txt
Normal file
3
HACKS.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Libs with customisations...
|
||||||
|
|
||||||
|
/tornado
|
|
@ -164,14 +164,16 @@ class Api(webserve.MainHandler):
|
||||||
self.set_header("Content-Type", "application/json")
|
self.set_header("Content-Type", "application/json")
|
||||||
try:
|
try:
|
||||||
out = json.dumps(dict, indent=self.intent, sort_keys=True)
|
out = json.dumps(dict, indent=self.intent, sort_keys=True)
|
||||||
callback = self.request.headers.get('callback', None) or self.request.headers.get('jsonp', None)
|
if 'jsonp' in self.request.query_arguments:
|
||||||
if callback != None:
|
out = self.request.arguments['jsonp'] + '(' + out + ');' # wrap with JSONP call if requested
|
||||||
out = callback + '(' + out + ');' # wrap with JSONP call if requested
|
|
||||||
except Exception, e: # if we fail to generate the output fake an error
|
except Exception, e: # if we fail to generate the output fake an error
|
||||||
logger.log(u"API :: " + traceback.format_exc(), logger.DEBUG)
|
logger.log(u"API :: " + traceback.format_exc(), logger.DEBUG)
|
||||||
out = '{"result":"' + result_type_map[RESULT_ERROR] + '", "message": "error while composing output: "' + ex(
|
out = '{"result":"' + result_type_map[RESULT_ERROR] + '", "message": "error while composing output: "' + ex(
|
||||||
e) + '"}'
|
e) + '"}'
|
||||||
return out
|
|
||||||
|
tornado_write_hack_dict = {'unwrap_json': out}
|
||||||
|
return tornado_write_hack_dict
|
||||||
|
|
||||||
def _grand_access(self, realKey, args, kwargs):
|
def _grand_access(self, realKey, args, kwargs):
|
||||||
""" validate api key and log result """
|
""" validate api key and log result """
|
||||||
|
|
|
@ -652,7 +652,10 @@ class RequestHandler(object):
|
||||||
if not isinstance(chunk, (bytes, unicode_type, dict)):
|
if not isinstance(chunk, (bytes, unicode_type, dict)):
|
||||||
raise TypeError("write() only accepts bytes, unicode, and dict objects")
|
raise TypeError("write() only accepts bytes, unicode, and dict objects")
|
||||||
if isinstance(chunk, dict):
|
if isinstance(chunk, dict):
|
||||||
chunk = escape.json_encode(chunk)
|
if 'unwrap_json' in chunk:
|
||||||
|
chunk = chunk['unwrap_json']
|
||||||
|
else:
|
||||||
|
chunk = escape.json_encode(chunk)
|
||||||
self.set_header("Content-Type", "application/json; charset=UTF-8")
|
self.set_header("Content-Type", "application/json; charset=UTF-8")
|
||||||
chunk = utf8(chunk)
|
chunk = utf8(chunk)
|
||||||
self._write_buffer.append(chunk)
|
self._write_buffer.append(chunk)
|
||||||
|
|
Loading…
Reference in a new issue