2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-02-16 10:39:23 +00:00

Have httpapi json dump try utf-8 first, but if the output is not utf-8, try cp1252

as it is a reasonable guess for firmware.  In short, OSes are presumed to trend toward utf-8, and firmware toward cp1252

If both fail, then inject DECODEERROR for now.
This commit is contained in:
Jarrod Johnson 2013-09-15 11:19:04 -04:00
parent eafdef413c
commit 782c1f9b9a

View File

@ -134,7 +134,12 @@ def resourcehandler(env, start_response):
else: #no keys, but a session, means it's hooking to receive data
sessid = querydict['session']
outdata = consolesessions[sessid].get_next_output(timeout=45)
rsp = json.dumps({'session': querydict['session'], 'data': outdata})
try:
rsp = json.dumps({'session': querydict['session'], 'data': outdata})
except UnicodeDecodeError:
rsp = json.dumps({'session': querydict['session'], 'data': outdata}, encoding='cp1252')
except UnicodeDecodeError:
rsp = json.dumps({'session': querydict['session'], 'data': 'DECODEERROR'})
start_response('200 OK', [('Content-Type',
'application/json; charset=utf-8')])
return [rsp]