Raise ClientDisconnect if disconnected while reading request body

This commit is contained in:
Tom Christie 2018-07-13 14:19:42 +01:00
parent 9eb5089d9b
commit 23a4b19505
1 changed files with 6 additions and 0 deletions

View File

@ -5,6 +5,10 @@ import json
import typing
class ClientDisconnect(Exception):
pass
class Request(Mapping):
def __init__(self, scope, receive=None):
self._scope = scope
@ -86,6 +90,8 @@ class Request(Mapping):
yield message.get("body", b"")
if not message.get("more_body", False):
break
elif message["type"] == "http.disconnect":
raise ClientDisconnect()
async def body(self):
if not hasattr(self, "_body"):