diff --git a/channels/generic/http.py b/channels/generic/http.py index d067717a2..ca5f470fb 100644 --- a/channels/generic/http.py +++ b/channels/generic/http.py @@ -43,6 +43,9 @@ async def send_body(self, body, *, more_body=False): await self.send( {"type": "http.response.body", "body": body, "more_body": more_body} ) + if not more_body: + await self.disconnect() + raise StopConsumer() async def send_response(self, status, body, **kwargs): """ @@ -78,11 +81,7 @@ async def http_request(self, message): if "body" in message: self.body.append(message["body"]) if not message.get("more_body"): - try: - await self.handle(b"".join(self.body)) - finally: - await self.disconnect() - raise StopConsumer() + await self.handle(b"".join(self.body)) async def http_disconnect(self, message): """