Always try to consume request body, plus minor cleanup.
This commit is contained in:
parent
85d58d7b2b
commit
9c21457b58
|
@ -78,11 +78,6 @@ class Http:
|
|||
raise ServerError("Handler produced no response")
|
||||
if self.stage is Stage.RESPONSE:
|
||||
await self.send(end_stream=True)
|
||||
# Consume any remaining request body (TODO: or disconnect?)
|
||||
if self.request_body:
|
||||
logger.error(f"{self.request} body not consumed.")
|
||||
async for _ in self:
|
||||
pass
|
||||
except CancelledError:
|
||||
# Write an appropriate response before exiting
|
||||
e = self.exception or ServiceUnavailable(f"Cancelled")
|
||||
|
@ -92,12 +87,14 @@ class Http:
|
|||
except Exception as e:
|
||||
# Write an error response
|
||||
await self.error_response(e)
|
||||
# Try to consume any remaining request body
|
||||
if self.request_body:
|
||||
if self.response and 200 <= self.response.status < 300:
|
||||
logger.error(f"{self.request} body not consumed.")
|
||||
async for _ in self:
|
||||
pass
|
||||
# Exit and disconnect if no more requests can be taken
|
||||
if (
|
||||
self.stage is not Stage.IDLE
|
||||
or self.request_body
|
||||
or not self.keep_alive
|
||||
):
|
||||
if self.stage is not Stage.IDLE or not self.keep_alive:
|
||||
break
|
||||
# Wait for next request
|
||||
if not self.recv_buffer:
|
||||
|
|
|
@ -228,7 +228,7 @@ class HttpProtocol(asyncio.Protocol):
|
|||
if self._task:
|
||||
self._task.cancel()
|
||||
if self._debug and self._http and self._http.response:
|
||||
ip = self._http.request.ip
|
||||
ip = self.transport.get_extra_info("peername")
|
||||
logger.error(f"Connection lost before response written @ {ip}")
|
||||
except Exception:
|
||||
logger.exception("protocol.connection_lost")
|
||||
|
|
Loading…
Reference in New Issue
Block a user