handle images and bytes

handle images and bytes
This commit is contained in:
Brian Martin 2020-01-20 12:36:36 -05:00
parent 346895eff3
commit f97c07ac7b

View file

@ -137,13 +137,18 @@ class ConfServer:
else: else:
proxymodelog.info(f"HTTP Proxy Request to EcoVacs (body=false) (host:{request.host}) - {ecorequest}") proxymodelog.info(f"HTTP Proxy Request to EcoVacs (body=false) (host:{request.host}) - {ecorequest}")
async with session.request(request.method, ecorequest) as resp: async with session.request(request.method, ecorequest) as resp:
ecoresp = await resp.text() if resp.content_type == "application/octet-stream":
ecoresp = await resp.read()
else:
ecoresp = await resp.text()
proxymodelog.info(f"HTTP Proxy Response from EcoVacs (URL: {ecorequest}) - (Status: {resp.status}) - {ecoresp}") proxymodelog.info(f"HTTP Proxy Response from EcoVacs (URL: {ecorequest}) - (Status: {resp.status}) - {ecoresp}")
if resp.status == 200: if resp.status == 200:
if resp.content_type == "application/json": if resp.content_type == "application/json":
ecoresp = json.loads(ecoresp) ecoresp = json.loads(ecoresp)
return web.json_response(ecoresp) return web.json_response(ecoresp)
elif resp.content_type == "application/octet-stream":
return web.Response(body=ecoresp)
else: else:
return web.Response(text=ecoresp) return web.Response(text=ecoresp)