Merge pull request #630 from 38elements/keep_alive

Refactor keep_alive
This commit is contained in:
Raphael Deem 2017-04-12 19:46:33 -07:00 committed by GitHub
commit e5d3fe52c5

View File

@ -89,6 +89,10 @@ class HttpProtocol(asyncio.Protocol):
self._last_request_time = None
self._request_handler_task = None
@property
def keep_alive(self):
return self.parser.should_keep_alive() and not self.signal.stopped
# -------------------------------------------- #
# Connection
# -------------------------------------------- #
@ -182,9 +186,7 @@ class HttpProtocol(asyncio.Protocol):
Writes response content synchronously to the transport.
"""
try:
keep_alive = (
self.parser.should_keep_alive() and not self.signal.stopped)
keep_alive = self.keep_alive
self.transport.write(
response.output(
self.request.version, keep_alive,
@ -218,9 +220,7 @@ class HttpProtocol(asyncio.Protocol):
"""
try:
keep_alive = (
self.parser.should_keep_alive() and not self.signal.stopped)
keep_alive = self.keep_alive
response.transport = self.transport
await response.stream(
self.request.version, keep_alive, self.request_timeout)