From 3a4fb289d9a19ea17dffc8ae8c29f50d708eb97a Mon Sep 17 00:00:00 2001 From: ziwon Date: Mon, 6 Mar 2017 15:13:27 +0900 Subject: [PATCH] fix keep-alive error when sending http pipeline --- sanic/server.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index 0c4bb4b8..4ee6268f 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -59,7 +59,8 @@ class HttpProtocol(asyncio.Protocol): # request config 'request_handler', 'request_timeout', 'request_max_size', # connection management - '_total_request_size', '_timeout_handler', '_last_communication_time') + '_total_request_size', '_timeout_handler', '_last_communication_time', + '_keep_alive') def __init__(self, *, loop, request_handler, error_handler, signal=Signal(), connections=set(), request_timeout=60, @@ -80,6 +81,7 @@ class HttpProtocol(asyncio.Protocol): self._timeout_handler = None self._last_request_time = None self._request_handler_task = None + self._keep_alive = False # -------------------------------------------- # # Connection @@ -142,6 +144,9 @@ class HttpProtocol(asyncio.Protocol): exception = PayloadTooLarge('Payload Too Large') self.write_error(exception) + if name == b'Connection': + self._keep_alive = value == b'keep-alive' + self.headers.append((name.decode().casefold(), value.decode())) def on_headers_complete(self): @@ -175,7 +180,7 @@ class HttpProtocol(asyncio.Protocol): """ try: keep_alive = ( - self.parser.should_keep_alive() and not self.signal.stopped) + self._keep_alive and not self.signal.stopped) self.transport.write( response.output(