Content-Type guessing
This commit is contained in:
@@ -291,10 +291,20 @@ async def response_from_context(context):
|
|||||||
await context["stream"].write_eof()
|
await context["stream"].write_eof()
|
||||||
return context["stream"]
|
return context["stream"]
|
||||||
else:
|
else:
|
||||||
return web.Response(
|
body = context["response_body"].getvalue()
|
||||||
body=context["response_body"].getbuffer(),
|
status = context["response_status"]
|
||||||
status=context["response_status"],
|
headers = context["response_headers"]
|
||||||
headers=context["response_headers"])
|
|
||||||
|
# Content-Type guessing (for demo only)
|
||||||
|
if "Content-Type" not in headers:
|
||||||
|
try:
|
||||||
|
body = body.decode("utf-8")
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
headers["Content-Type"] = "text/plain"
|
||||||
|
|
||||||
|
return web.Response(body=body, status=status, headers=headers)
|
||||||
|
|
||||||
|
|
||||||
def generate_endpoint(code):
|
def generate_endpoint(code):
|
||||||
|
|||||||
Reference in New Issue
Block a user