From 94d5536bcd0a3897db2158cfa6ce643432d33d0d Mon Sep 17 00:00:00 2001 From: noO0oOo0ob <38344038+noO0oOo0ob@users.noreply.github.com> Date: Mon, 22 Jan 2024 20:24:43 +0800 Subject: [PATCH] change request post handler to async (#821) * change request post handler to async * version --- lyrebird/mock/handlers/handler_context.py | 14 +++++++++----- lyrebird/version.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lyrebird/mock/handlers/handler_context.py b/lyrebird/mock/handlers/handler_context.py index 591dd4f5d..e8d120703 100644 --- a/lyrebird/mock/handlers/handler_context.py +++ b/lyrebird/mock/handlers/handler_context.py @@ -240,7 +240,9 @@ def generator(): self.server_resp_time = time.time() yield _resp_data[ i * size : (i+1) * size ] finally: - self.update_client_resp_time() + def request_post_handler(): + self.update_client_resp_time() + application.server['task'].add_task('request_post', request_post_handler) return generator def _generator_stream(self): @@ -259,11 +261,13 @@ def generator(): self.server_resp_time = time.time() yield item finally: - self.response.data = b''.join(buffer) - DataHelper.origin2flow(self.response, output=self.flow['response'], chain=self.response_chain) + def request_post_handler(): + self.response.data = b''.join(buffer) + DataHelper.origin2flow(self.response, output=self.flow['response'], chain=self.response_chain) - self.update_client_resp_time() - upstream.close() + self.update_client_resp_time() + upstream.close() + application.server['task'].add_task('request_post', request_post_handler) return generator def update_response_headers_code2flow(self, output_key='response'): diff --git a/lyrebird/version.py b/lyrebird/version.py index 5b4735c56..a9580ff9c 100644 --- a/lyrebird/version.py +++ b/lyrebird/version.py @@ -1,3 +1,3 @@ -IVERSION = (2, 23, 5) +IVERSION = (2, 24, 0) VERSION = ".".join(str(i) for i in IVERSION) LYREBIRD = "Lyrebird " + VERSION