Workaround missing content-type, and formatting issues seen from some agents

Change-Id: I64f3375c0ed9a68cd620231ab14d17299840a97c
This commit is contained in:
Vitaliy Kharechko 2016-08-03 10:59:01 +03:00
parent 886c187e2f
commit 198943af58

View File

@ -132,7 +132,7 @@ class BroadViewCollector(object):
if handled: if handled:
for y in self._publishers: for y in self._publishers:
code = y.publish(src, o) code = y.publish(src, o)
if not code == 200: if not code == 200:
LOG.info("handlePOST: {} failed to publish, code: {}".format(y, code)) LOG.info("handlePOST: {} failed to publish, code: {}".format(y, code))
retcode = 200 retcode = 200
break break
@ -151,7 +151,7 @@ class HTTPRequestHandler(BaseHTTPRequestHandler):
except: except:
e = sys.exc_info()[0] e = sys.exc_info()[0]
LOG.info("broadview_collector: do_POST missing content-type {}".format(e)) LOG.info("broadview_collector: do_POST missing content-type {}".format(e))
ctype = None ctype = "application/json"
try: try:
length = int(self.headers.getheader('content-length')) length = int(self.headers.getheader('content-length'))
except: except:
@ -159,7 +159,11 @@ class HTTPRequestHandler(BaseHTTPRequestHandler):
LOG.info("broadview_collector: do_POST missing content-length {}".format(e)) LOG.info("broadview_collector: do_POST missing content-length {}".format(e))
length = 0 length = 0
if ctype and "json" in ctype.lower(): if ctype and "json" in ctype.lower():
data = ast.literal_eval(json.loads(self.rfile.read(length))) c = self.rfile.read(length)
try:
data = ast.literal_eval(json.loads(c))
except:
data = json.loads(c)
code = collector.handlePOST(self.path, ctype, length, self.client_address[0], data ) code = collector.handlePOST(self.path, ctype, length, self.client_address[0], data )
data = json.dumps({}) data = json.dumps({})
try: try: