Wait until all data in buffer is flushed to client when upstream server finishes.

This commit is contained in:
yk 2024-02-28 17:06:37 +08:00
parent 30574fd041
commit d7765067b0
1 changed files with 14 additions and 8 deletions

View File

@ -37,6 +37,8 @@ class HttpProtocolHandler(BaseTcpServerHandler[HttpClientConnection]):
Accepts `Client` connection and delegates to HttpProtocolHandlerPlugin.
"""
server_teared = False
def __init__(self, *args: Any, **kwargs: Any):
super().__init__(*args, **kwargs)
self.start_time: float = time.time()
@ -145,15 +147,19 @@ class HttpProtocolHandler(BaseTcpServerHandler[HttpClientConnection]):
teardown = await self.plugin.write_to_descriptors(writables)
if teardown:
return True
# Read from ready to read sockets
teardown = await self.handle_readables(readables)
if teardown:
return True
# Invoke plugin.read_from_descriptors
if self.plugin:
teardown = await self.plugin.read_from_descriptors(readables)
if not self.server_teared:
# Read from ready to read sockets
teardown = await self.handle_readables(readables)
if teardown:
return True
self.server_teared = True
# Invoke plugin.read_from_descriptors
if self.plugin:
teardown = await self.plugin.read_from_descriptors(readables)
if teardown:
self.server_teared = True
if self.server_teared and not self.work.has_buffer():
# Wait until client buffer flushed when server teared down.
return True
return False
def handle_data(self, data: memoryview) -> Optional[bool]: