def guess_response(self, value):
resp = value.response
if type(resp) in (dict, list, int, float, bool):
resp = aioResponse(body=bytes(json.dumps(resp, cls=GuillotinaJSONEncoder), 'utf-8'))
resp.headers['Content-Type'] = 'application/json'
elif isinstance(resp, str):
original_resp = resp
resp = aioResponse(body=bytes(resp, 'utf-8'))
if '<html' in original_resp:
resp.headers['Content-Type'] = 'text/html'
else:
resp.headers['Content-Type'] = 'text/plain'
elif resp is None:
# missing result...
resp = aioResponse(body=b'{}')
resp.headers['Content-Type'] = 'application/json'
resp.headers.update(value.headers)
if not resp.prepared:
resp.set_status(value.status)
return resp
评论列表
文章目录