From 23a4b19505a0232612ddf431e63ed20d04082d9e Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 13 Jul 2018 14:19:42 +0100 Subject: [PATCH] Raise ClientDisconnect if disconnected while reading request body --- starlette/request.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/starlette/request.py b/starlette/request.py index 49d19510..4d7ae6aa 100644 --- a/starlette/request.py +++ b/starlette/request.py @@ -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"):