fix keep-alive error when sending http pipeline

This commit is contained in:
ziwon 2017-03-06 15:13:27 +09:00
parent 19592e8eea
commit 3a4fb289d9

View File

@ -59,7 +59,8 @@ class HttpProtocol(asyncio.Protocol):
# request config # request config
'request_handler', 'request_timeout', 'request_max_size', 'request_handler', 'request_timeout', 'request_max_size',
# connection management # 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, def __init__(self, *, loop, request_handler, error_handler,
signal=Signal(), connections=set(), request_timeout=60, signal=Signal(), connections=set(), request_timeout=60,
@ -80,6 +81,7 @@ class HttpProtocol(asyncio.Protocol):
self._timeout_handler = None self._timeout_handler = None
self._last_request_time = None self._last_request_time = None
self._request_handler_task = None self._request_handler_task = None
self._keep_alive = False
# -------------------------------------------- # # -------------------------------------------- #
# Connection # Connection
@ -142,6 +144,9 @@ class HttpProtocol(asyncio.Protocol):
exception = PayloadTooLarge('Payload Too Large') exception = PayloadTooLarge('Payload Too Large')
self.write_error(exception) self.write_error(exception)
if name == b'Connection':
self._keep_alive = value == b'keep-alive'
self.headers.append((name.decode().casefold(), value.decode())) self.headers.append((name.decode().casefold(), value.decode()))
def on_headers_complete(self): def on_headers_complete(self):
@ -175,7 +180,7 @@ class HttpProtocol(asyncio.Protocol):
""" """
try: try:
keep_alive = ( keep_alive = (
self.parser.should_keep_alive() and not self.signal.stopped) self._keep_alive and not self.signal.stopped)
self.transport.write( self.transport.write(
response.output( response.output(