From 7fe418d1b7c0d6fd03104f8a641da5c08a114da6 Mon Sep 17 00:00:00 2001 From: 38elements Date: Wed, 12 Apr 2017 17:55:22 +0900 Subject: [PATCH] Refactor keep_alive --- sanic/server.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index 7868836c..40c3ee69 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -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)