mirror of https://github.com/encode/starlette.git
Raise ClientDisconnect if disconnected while reading request body
This commit is contained in:
parent
9eb5089d9b
commit
23a4b19505
|
@ -5,6 +5,10 @@ import json
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
||||||
|
class ClientDisconnect(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Request(Mapping):
|
class Request(Mapping):
|
||||||
def __init__(self, scope, receive=None):
|
def __init__(self, scope, receive=None):
|
||||||
self._scope = scope
|
self._scope = scope
|
||||||
|
@ -86,6 +90,8 @@ class Request(Mapping):
|
||||||
yield message.get("body", b"")
|
yield message.get("body", b"")
|
||||||
if not message.get("more_body", False):
|
if not message.get("more_body", False):
|
||||||
break
|
break
|
||||||
|
elif message["type"] == "http.disconnect":
|
||||||
|
raise ClientDisconnect()
|
||||||
|
|
||||||
async def body(self):
|
async def body(self):
|
||||||
if not hasattr(self, "_body"):
|
if not hasattr(self, "_body"):
|
||||||
|
|
Loading…
Reference in New Issue